I can’t seem to determine any difference between InputStreamReader and FileReader besides the way the two are initialized. Is there any benefit to using one or the other? Most other articles cover FileInputStream vs InputStreamReader, but I am contrasting with FileReader instead. Seems to me they both have the same purpose.
I can’t seem to determine any difference between InputStreamReader and FileReader besides the way
Share
First,
InputStreamReadercan handle all input streams, not just files. Other examples are network connections, classpath resources and ZIP files.Second,
FileReaderuntil Java 11 did not allow you to specify an encoding and instead only used the plaform default encoding, which made it pretty much useless as using it would result in corrupted data when the code is run on systems with different platform default encodings.Since Java 11,
FileReaderis a useful shortcut for wrapping anInputStreamReaderaround aFileInputStream.