Java Read file garbled

Source: Internet
Author: User

private void FileReader () throws ioexception{
BufferedReader bf= New BufferedReader (New InputStreamReader (New FileInputStream ("d:\\comparedll.py"), "UTF-8");
String str= "";
while ((Str=bf.readline ())!=null) {
System.out.println (str);

}
Bf.close ();
}

If you do not specify the encoding, the system default encoding is used when reading the file, typically GBK

I/O class handling for Java

The reader class is the parent of the read characters in Java I/O, and the InputStream class is the parent class of the read Byte, and the InputStreamReader class is the association of byte-to-character bridges, which is responsible for processing read byte-to-character conversions during I/O processes. and the specific byte-to-character decoding implementation It is implemented by Streamdecoder, in the Streamdecoder decoding process must be specified by the user Charset encoding format. It is important to note that if you do not specify Charset, the default character set in the local environment will be used, such as GBK encoding in the Chinese environment.

Java Read file garbled

Related Article

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.