1. Special methods for character buffer streams
BufferedWriter:
1 Public void newLine (): depending on the system to determine the line break
BufferedReader:
1 Public String readLine (): reads one row of data at a time
A string containing the contents of the row, with no line terminator, or null if the end of the stream has been reached
2. code example:
1 Packagecn.itcast_05;2 3 ImportJava.io.BufferedReader;4 ImportJava.io.BufferedWriter;5 ImportJava.io.FileReader;6 ImportJava.io.FileWriter;7 Importjava.io.IOException;8 9 /*Ten * Special methods for character buffer streams: One * BufferedWriter: A * public void NewLine (): Based on system to determine line break - * BufferedReader: - * Public String ReadLine (): reads one row of data at a time the * A string containing the contents of the row, with no line terminator, or null if the end of the stream has been reached - */ - Public classBuffereddemo { - Public Static voidMain (string[] args)throwsIOException { + //write (); - read (); + } A at Private Static voidRead ()throwsIOException { - //creating a character buffer input stream object -BufferedReader br =NewBufferedReader (NewFileReader ("Bw2.txt")); - - //Public String ReadLine (): reads one row of data at a time - //String line = Br.readline (); in //System.out.println (line); - //Line = Br.readline (); to //System.out.println (line); + - //The final version of the code theString line =NULL; * while(line = Br.readline ())! =NULL) { $ System.out.println (line);Panax Notoginseng } - the //Freeing Resources + br.close (); A } the + Private Static voidWrite ()throwsIOException { - //creating a character buffered output stream object $BufferedWriter BW =NewBufferedWriter (NewFileWriter ("Bw2.txt")); $ for(intx = 0; x < 10; X + +) { -Bw.write ("Hello" +x); - //bw.write ("\ r \ n"); the bw.newline (); - Bw.flush ();Wuyi } the bw.close (); - } Wu -}
Java Fundamentals Hardening IO Stream Note 39: The special function of the character stream buffer stream