Java filereader/filewriter read-write files

Source: Internet
Author: User

Java Filereader/filewriter Read and write letters and numbers is no problem, but read and write Chinese characters are garbled. Record, then find the solution and then fill it up.

public static void Main (string[] args) {

FileReader FR = null;

FileWriter FW = NULL;

try {

int a = 0;

FR = new FileReader ("C:/a.txt");//Read target

FW = new FileWriter ("C:/b.txt");//write to target

while ((A=fr.read ())!=-1) {

System.out.print ((char) A + "");//console displays the file being read

Fw.write ((char) a);//write once per read

}

Fw.flush ();//Refresh flushes the files read directly to the local destination file

} catch (FileNotFoundException e) {

TODO auto-generated Catch block

E.printstacktrace ();

} catch (IOException e) {

TODO auto-generated Catch block

E.printstacktrace ();

}

finally{

try {

Fw.close ();//Last remember to close the resource

} catch (IOException e) {

TODO auto-generated Catch block

E.printstacktrace ();

}

}

}

Java filereader/filewriter read-write files

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.