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 system.in 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 (system.in); 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: http://blog.csdn.net/u012355386/article/details/22697155 easy to understand, very useful
"Reprint" The basic rule summary of IO flow operation in Java