ext.: http://blog.csdn.net/joephoenix/articles/2283165.aspx
The IO stream of Java is divided into two kinds of streams
byte stream InputStream OutputStream
Character Stream Reader Writer
They're all abstract classes.
Specific implementation
byte stream FileInputStream FileOutputStream
Character Stream FileReader FileWriter
A character stream processes a cell that is 2-byte Unicode characters, manipulating characters, character arrays, or strings, and a byte-stream processing unit of 1 bytes, manipulating bytes and byte arrays. So a character stream is a character that is converted from a Java virtual machine to a 2-byte Unicode character, so it's better for multi-language support! If it is audio files, pictures, songs, use a word throttle better, if it is related to Chinese (text), with a character stream better.
All of the files are stored in byte (byte) storage, and the characters that are not files on the disk are encoded into bytes, and then the bytes are stored to disk. When reading a file (especially a text file), it is also a byte-by-byte read to form a sequence of bytes.
Byte streams can be used for any type of object, including binary objects, whereas character streams only handle characters or strings; 2. The byte stream provides the ability to handle any type of IO operation, but it cannot handle Unicode characters directly, and a character stream is available.
Byte streams can be converted to character stream with Inputsteamreader OutputStreamWriter
Convert to Bufferdreader bufferedwriter they have buffers
Example: Read file from byte stream input to character stream input
Define a byte stream:
Defines a pointer to D:/text. TXT Byte stream
FileInputStream FileInputStream = new FileInputStream ("D:/text.txt");
Convert bytes to InputStreamReader
InputStreamReader InputStreamReader = new InputStreamReader (FileInputStream);
InputStreamReader converted to BufferedReader with cache
BufferedReader BufferedReader = new BufferedReader (Inputsteamreader);
You can assign the read content to a character
string ss = new string ();
String s;
while ((s = bufferedreader.readline ())!=null) {
SS + = s;
}
Example: Write file from byte stream output to character stream output
FileOutputStream FileOutputStream = new FileOutputStream ("D:/text.txt"); Defines a pointer to D:/text. TXT file
OutputStreamWriter outputstreamwriter = new OutputStreamWriter (FileOutputStream);
BufferedWriter bufferedwriter = new BufferedWriter (outputstreamwriter);
Bufferedwriter.write (s);
Bufferedwriter.close ();
Outputstreamwriter.close ();
Fileoutputstream.close ();
java--file operation character stream and byte stream difference