FileReader
Origin
In FileUtil
, a lot of static encapsulation had already been done for file reading operations. However, according to the principle of separation of responsibilities, I felt it necessary to encapsulate a separate class for file reading, to make the project clearer. Of course, using FileUtil
to operate on files is the most convenient.
Usage
In the JDK, there is also a FileReader
class, but it is not as convenient as imagined. Therefore, Hutool provides a more convenient FileReader
class.
// Default encoding is UTF-8. The second parameter can be passed in the constructor as the encoding.
FileReader fileReader = new FileReader("test.properties");
String result = fileReader.readString();
FileReader
provides the following methods to quickly read the file content:
readBytes
readString
readLines
In addition, this class provides the following methods for converting to a stream or BufferedReader
:
getReader
getInputStream