Java — reading from a file. Input stream vs. reader

后端 未结 3 541
清酒与你
清酒与你 2020-12-31 06:11

In every Java implementation I see of reading from a file, I almost always see a file reader used to read line by line. My thought would be that this would be terribly ineff

3条回答
  •  梦谈多话
    2020-12-31 07:15

    FileReader is generally used in conjunction with a BufferedReader because frequently it makes sense to read a file line by line, specially if the file has a well-defined record structure where each record corresponds to a line.

    Also, FileReader can simplify some of the work for dealing with character encodings and conversions, as stated in the javadocs :

    Convenience class for reading character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are appropriate ... FileReader is meant for reading streams of characters.

提交回复
热议问题