InputStreamReader and BufferedReader. One of the most important classes is InputStreamReader, which is a bridge that converts bytes into characters. You can specify the encoding in the constructor, and if you do not specify it, the default encoding for the underlying operating system, such as GBK, is used.
FileReader and InputStreamReader involve encoding conversions (specifying encoding or using OS default encoding) to
Can appear garbled on different platforms! The FileInputStream is processed in binary mode, and there is no garbled phenomenon.
The FileInputStream byte stream is read in a single bit of bytes.
The FileReader character stream is read in a single character.
The InputStreamReader byte is converted to a character.
BufferedReader reads a large number of character streams.
InputStream reads one byte at a time, and I/O is performed once per read.
BufferedReader bufreader = null;
InputStreamReader ISR = null;
FileReader FR = null;
try {
for (String filename:filenames) {
method One:
ISR = new InputStreamReader (New FileInputStream ("D:\test.txt"), "Utf-8");
Bufreader = new BufferedReader (ISR);
Method Two:
fr = new FileReader ("D:\test.txt" );
Bufreader = new BufferedReader (FR);
while (Bufreader.ready ()) {
1. Get each row of data
String dataline = Bufreader.readline ();
}
}
Reference: http://blog.sina.com.cn/s/blog_6fda308501012mf0.html
Http://www.360doc.com/content/12/1009/16/10630456_240458246.shtml
The difference between InputStreamReader and FileReader