Java IO garbled

Source: Internet
Author: User

InputStreamReader ISR = new InputStreamReader (New FileInputStream ("./test/Junk SMS Training set 80W"), "UTF-8");
FileReader FR = new FileReader (New File ("./test/Spam Message training set 80W"));
BufferedReader br = new BufferedReader (ISR);

FileWriter FW = new FileWriter ("./test/Spam Message training set 80W _result.txt"), true);
OutputStreamWriter OSW = new OutputStreamWriter (New FileOutputStream ("./test/Junk SMS Training set 80W _result.txt"), "UTF-8");
BufferedWriter bw = new BufferedWriter (OSW);

The problem is that in the process of FileReader reading a file, FileReader inherits InputStreamReader, but does not implement a constructor with character set parameters in the parent class.

The reason is clear, the problem is not difficult to solve, with inputstreamreader instead of FileReader,
InputStreamReader isr=new InputStreamReader (New FileInputStream (FileName), "UTF-8");
This reads the file directly with the UTF-8 decoding, no longer do the encoding conversion.

Java IO garbled

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.