Summary of basic rules of IO flow operation in Java "reprint"

Source: Internet
Author: User

The basic rules of flow operation: three clear 1. Source: input stream reads stream inputstream,reader purpose: The output stream is written to stream OutputStream, Writer2. Whether the data that is explicitly manipulated is a plain text file or if the text file uses a character stream Reader or writer, is not a plain text file using byte stream InputStream or OUTPUTSTREAM3. When the system is clear, the specific applicable object; Differentiate source device by device: Memory hard disk keyboard purpose device: Memory HDD Console ********** EG1: Copying data from one text file to another file analysis start: source is a text This file therefore uses a character stream, because to read the data in the area, select Reader next explicitly use the object, the device is the file on the hard disk, the reader system in the operation of the object of the file FileReader filereader fr=new filereader (" A.txt "), in order to improve read efficiency, join the buffer BufferedReader in the reader system ( Decoration class) BufferedReader Br=new bufferedreader (FR); Purpose: is also a file, because to write data to it, select writer because the file also exists with the hard disk, Therefore, the object Filewriterfilewriter fw=new filewriter ("B.txt") is used to manipulate the file in the Writer system; In the same vein, in order to improve reading efficiency, join  Writer  Buffer Bufferedwriterbuffered writer  br=new buffered writer r (FW) in the system; if the picture, Audio or video files, the analysis step as above, changed to the corresponding byte stream. EG2: Saving keyboard input data to a file Analysis: Source is keyboard input ( inputstream,reader), is plain text (Reader); device: keyboard, corresponding object because the system is Reader, and system is a byte stream (InputStream), So to turn into a character stream, using the reader system in the byte-to-characters bridge: Inputstreamreaderinputstreamreader Isr=new inputstreamreader (; To improve efficiency, use Bufferedreaderbufferedreader Br=new bufferedreader (ISR);  purposes: Also text files, writer devices: Files on the hard disk, Use the object Filewriterfilewriter fw=new filewriter ("A.txt"), also to improve efficiency:buffered writer  br=new  Buffered writer r (FW); If you want to output the files in the text to the console, follow the three above to make it clear.   Original blog: easy to understand, very useful

"Reprint" The basic rule summary of IO flow operation in Java

Related Article

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: 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.