/* characters written to buffer stream buffers appear in order to improve the operational efficiency of the stream. So before you create a buffer, you must have an existing stream object. Writer corresponds to Bufferedwriterreader bufferedreader the buffer provides a line break method, NewLine (); */import Java.io.*;class Bufferedwriterdemo {public static void main (string[] args) throws Ioexception{filewriter fw=new FileWriter ("d:/myfile/ Mycode/3.txt ");//Create a character to write to the stream object. BufferedWriter bw=new BufferedWriter (FW);//In order to improve the character writing flow efficiency, the buffer technology is added. Simply pass the stream object that needs to be improved as an argument to the constructor of the buffer. Bw.write ("ABCDE"); Bw.newline ();//newline character bw.write ("HelloWorld"), Bw.flush ();//NOTE: If the buffer is used, the Bw.close () will be refreshed ();//Closing the buffer is closing the stream resource , so there is no need for fw.close ();}}
/* character read stream buffer. This buffer provides a way to read one line at a time, facilitating the acquisition of text data. The method is ReadLine () when NULL is returned to indicate that the end of the file is read. */import java.io.*;class Bufferedreaderdemo {public static void main (string[] args) throws Ioexception{filereader Fr=new FileReader ("D:/myfile/mycode/3.txt"); BufferedReader br=new BufferedReader (FR); String Line=null;while ((Line=br.readline ())!=null) {System.out.println (line);}}}
Java IO stream two-character stream input and output buffers