Bufferedwriter:java program------>test.txt
Primary method: void Write (char ch);//write a single character.
void Write (char []cbuf,int off,int len)//writes a portion of the character data.
void Write (String s,int off,int len)//writes a portion of the string.
void NewLine ()//writes a line delimiter.
void Flush ();//refreshes the buffer in the stream. Write the buffered data to the destination file.
void close ();//closes the stream and refreshes it before closing.
Public classBufferedwriterdemo { Public Static voidMain (string[] args)throwsIOException {FileWriter fw=NewFileWriter ("Buffered.txt");//fw.write ("ok168");//fw.close (); /*** In order to improve the efficiency of writing, a buffer of character stream is used. * Creates a buffer object that writes a character to the stream and associates it with the flow object specified to be buffered. */BufferedWriter BUFW=NewBufferedWriter (FW); //writes data to the buffer using a method in the buffer. Bufw.write ("Hello World!")); Bufw.newline (); Bufw.newline (); Bufw.write ("!hello World!"); Bufw.write ("!hello World!"); //use the methods in the buffer to flush the data to the destination file. Bufw.flush (); //closes the buffer while closing the FW stream objectBufw.close (); }}
BufferedReader:test.txt------The >java program
Construction method: BufferedReader br = new Bufferreader (Reader in);
Main methods: int read (); Reads a single character.
int read (char[] cbuf,int off,int len);//reads a character into a part of the array. Returns the number of characters read. Reach the tail, return-1.
String ReadLine (); Reads a line of text.
void Close (); Closes the stream. and frees all resources associated with the stream.
1 Public classBufferreaderdemo {2 //d:/test.txt------The >java program3 Public Static voidMain (string[] args)throwsException {4FileReader FR =NewFileReader ("D:/test.txt");5BufferedReader br =NewBufferedReader (FR);6 7 //String str = br.readline ();8 //While (str! = null) {9 //System.out.println (str);Ten //str = br.readline (); One // } A -String str= ""; - while((Str=br.readline ())! =NULL){ the System.out.println (str); - } - - + } - +}
Java Io-file (Buffered stream)