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