The difference between InputStreamReader and FileReader

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.