Some basic operations on the flow

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.