Buffer Flow Overview
- Input and output stream is buffered with a buffer stream
- Buffer flow can significantly reduce the number of our access to IO, protect the hard disk!
- The processing flow itself is a buffered stream (flow wrap), a buffered stream flow must be attached to the node (original stream)
- Process flow stream is wrapped in the original node, corresponding to wrap the pipe in the pipeline
Create a character stream read file object:
BufferedReader br = new BufferedReader(new FileReader("readme.txt"));
Create a character stream write file object:
BufferedWriter bw = new BufferedWriter(new FileWriter("dest.txt"));
Read and write data while loop:
char [] = CHS new new char [2048 ]; int len; the while ((len = br.read (CHS)) = -1! ) { bw.write (CHS ); }
bw.flush (); // remember refreshed buffer flow
Close resources:
br.close();
bw.close();
Of course, with the buffer flow it is also possible to copy files, highly efficient!