Top 43 Java IO and File System Interview Questions with Answers for 1 to 3 Years Experienced

Good knowledge of Java IO API is important for any Java developer but many of them barely pay attention to Java IO and NIO API, and that's why they often struggle during Java interviews when a question related to Input-Output operation is asked. In the past, I have shared many Java interview questions on topics like Collections, Concurrency, JVM internals, Garbage Collection, OOP, Design Patterns, and Data structure based coding problems, which received good feedback and helped many Java developer on their Java Interview preparation. Consequently, many of my readers were also asking about Java IO and File-based interview questions and this was one of the pending items on my TODO list for quite some time.

Difference between FileReader vs FileInputStream in Java? Answer

Even though both FileReader and FileInputStream are used to read data from a file in Java, they are quite different. The main difference between the FileReader and FileInputStream is that one reads data from a character stream while the other reads data from a byte stream. The FileReader automatically converts the raw bytes into characters by using the platform's default character encoding. This means you should use this class if you are reading from a text file that has the same character encoding as the default one.