The role of buffered streams:
If the stream is not buffered, the program reads a data and writes a data. This greatly affects the efficiency in a program with large data volumes.
The buffer stream function is to write the data to the buffer, wait for the buffer full, and then write the data into the file. So the efficiency is greatly improved.
About the operation rules of various flows:
The reason to understand this rule is because there are too many objects, and the development does not know which object is appropriate. Therefore, only the following four points need to be clarified:
1, clear source and purpose:
Source: InputStream (Byte stream) Reader (character stream)
Purpose: OutStream (Byte stream) Writer (character stream)
2, clear whether the data is plain text data such as 1: if plain text data: source Reader
Source: Is Reader Is Writer.
No InputStream
The purpose of the Writer is to set Spare Drive: File
No OutStream there is File Reader in=new FileReader ("path");
Here you can determine whether to use which system FileWriter out=new FileWriter ("path");
3, it is clear that the specific equipment needs efficient function (buffering Flow):
Source. Keyboard: system.in Hard disk: File Memory: Array network: Socket stream BufferedReader bufi= new Bufferedrea Der (FileReader ("path"));
Objective. Console: System.out hard disk: File Memory: Array network: Socket stream bufferedwriter bufw= new BufferedWriter (Fi Lewriter ("path"));
4, whether additional features are required:
Need to be efficient (buffer): Buffer
Example two: Read the keyboard input (bytes) information, and write to a file. You need to convert byte streams into a character stream, and you need efficient functionality
inputstreamreader in=new inputstreamreader (system.in);
FileWriter out=new FileWriter ("path");
Efficient buffers: BufferedReader bufi=new BufferedReader (New InputStreamReader (system.in));
BufferedWriter bufw=new BufferedWriter (New FileWriter ("path"));
Some basic operations on the flow