Java FileReader and FileWriter
Overview
Character streams are IO streams that can read characters directly
Character stream to read the characters, it is necessary to read the byte data first, then convert to the character. If you want to write a character, you need to convert the character to byte and write
Whether a character stream can copy files that are not plain text. Files that are not text-less can be copied because the bytes are converted to characters when they are read, and the corresponding characters may not be found in the conversion process. Instead, write the characters into bytes to write out, if it is?, write directly, so that the file after writing a mess, can not see the copy file example
filereader reader = null;
FileWriter writer = null;
try{//Create input/output stream reader = new FileReader ("E:/readme.txt");
writer = new FileWriter ("D:/temp.txt");
char[] buffer = new char[1024 * 8];
int Len;
Read and write data while (len = reader.read (buffer) > 0) {writer.write (buffer, 0, Len);
} System.out.println ("done."); }catch (IOException e) {e.printstacktrace ();}
finally {try{//close the input stream if (reader!= null) {reader.close ();
}}catch (IOException e) {e.printstacktrace ();
}finally {try {//Turn off output stream if (writer!= null) {writer.close ();
} catch (IOException e) {e.printstacktrace (); }
}
}