Java Fundamentals Review Javaio---InputStreamReader and outputstreamwriter conversion flows

Source: Internet
Author: User

InputStreamReader: is a bridge of byte flow to character stream;

OutputStreamWriter is a bridge of character flow to byte stream;

 PackageCom.lp.ecjtu;ImportJava.io.BufferedReader;ImportJava.io.BufferedWriter;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.InputStreamReader;ImportJava.io.OutputStream;ImportJava.io.OutputStreamWriter;ImportJava.io.Writer; Public classSystemreadinkeytranfer {/**     * 1. Source: Keyboard * Purpose: Console * 2. Source: Keyboard Input: Store keyboard input data into a file * Purpose: File * 3. Source: File: Print data from file on Console * Purpose: Console * Flow operation The basic process: * Through two clear to complete * 1 Clear source and purpose * Source: input stream, InputStream Reader * Purpose: Output stream: OutputStream Write     R * 2. Whether the operation is plain text * is: Character stream * is not: Byte stream * 3. When the system is clear, which specific object to use. * by device to differentiate: * source device: Memory, hard disk, keyboard * Purpose: Memory, HDD, console * 1. Store the data in one text file into another file.     Copy the file. * Source: Read stream is used because it is the source. InputStream Reader * is a text file: It is possible to select the reader * explicit device: A file on the hard disk * The reader system can manipulate the file FileReader * whether to mention     High efficiency, is to join the reader system in the BufferedReader * FileReader fr = new FileReader ("A.txt");     * BufferedReader BUFFR = new BufferedReader (FR); * * Purpose: OutputStream Writer * is plain text, yes!     Use a character stream Reader.     * Device: The file on the hard disk. * Whether the FileWriter in the writer system can be manipulated to improve efficiency, is to join the writer system BufferedWriter * FileWriter FR = new Filew     Riter ("A.txt"); * BufFeredwriter BUFFR = new BufferedWriter (FR); * 2. Store the data in one picture file to another file.      Copy the file.*/     Public Static voidMain (string[] args) {BufferedReader Bufferr=NULL; BufferedWriter Bufferw=NULL; Try {            //the System.in->inputstream->reader object//wrapping a Reader object as a BufferedReader object//Keyboard Entry /*Bufferr = new BufferedReader (new InputStreamReader (system.in));//store keyboard input data in OUT.txt file bufferw= new Bufferedw Riter (New OutputStreamWriter (New FileOutputStream ("OUT.txt" ));*/            //Link the data in the file to the BufferedReader, InputStreamReader the bridge to the character conversion. Bufferr =NewBufferedReader (NewInputStreamReader (NewFileInputStream ("Filereaderdemo.java"))); //Print the file's data to the console, outputstreamwriter the character to the byte conversion bridgeBUFFERW =NewBufferedWriter (NewOutputStreamWriter (System.out)); String Line=NULL; //read one by one in a circular way                 while((Line=bufferr.readline ())! =NULL){                    //if the read string is "Over", the program exits                    if(Line.equals ("Over") {system.exit (-1);//or with a break.                    }                    //Print the Read content//System.out.println (Line.touppercase ()); //output using a character output streamBufferw.write (Line.touppercase ()); Bufferw.newline ();//cross-platform line breaks, no ' \ r \ n 'Bufferw.flush (); }            } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }finally{                Try {                        if(Bufferr! =NULL) {bufferr.close (); }                        if(Bufferw! =NULL) {bufferw.close (); }                    } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }                }                            }        }

Java Fundamentals Review Javaio---InputStreamReader and outputstreamwriter conversion flows

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.