Character stream for efficient reading and writing, also provides the corresponding characters buffer stream.
Character Buffer stream:
A, BufferedWriter: Character buffered output stream
B, BufferedReader: character buffered input stream
A, BufferedWriter: Character buffered output stream
Writes text to the character output stream, buffering individual characters, providing efficient writes of individual characters, arrays, and strings.
You can specify the size of the buffer, or accept the default size. In most cases, the default value is large enough.
1 //character buffered input stream 2 bufferedwriter bw = new BufferedWriter (New outputstreamwriter (3 new FileOutputStream (" A.txt ")));
* //Simplified version:
* bufferedwriter BW = new BufferedWriter (New FileWriter ("A.txt")); 4 bw.write ("hehe"), 5 bw.write ("This is a"), 6 bw.write ("cold joke"); 7 8 bw.close ( ), ten}
B, BufferedReader: character buffered input stream
Reads text from the character input stream, buffering individual characters, enabling efficient reading of characters, arrays, and rows.
You can specify the size of the buffer, or you can use the default size. In most cases, the default value is large enough.
1 //character buffer input stream2BufferedReader br =NewBufferedReader (NewFileReader ("A.txt"));3 intLen = 0;4 Char[] ch =New Char[1024];5 while(len = br.read (ch))! =-1){6System.out.println (NewString (Ch,0,len));//Print the contents of the a.txt in a string way7 }8 9 Ten //Freeing Resources OneBr.close ();
Java 12-5 character stream with buffer