07JavaIO Explanation of character stream

Source: Internet
Author: User

The character stream is very simple if the byte stream is mastered well. The routines are the same, except that the character stream is a string.

The character stream is described as follows:

The top-level reader of the character stream corresponds to the inputstream,writer in the byte stream corresponding to OutputStream.

Describe the class hierarchy of reader in the IO system:

Writer class level:

Let's take a look at the two most important classes in the character stream:

These two names make interesting, that is, the byte stream and the character stream of the top-level class splicing together.

Both of these are specific classes.

Describe the constructors of the InputStreamReader and OutputStreamWriter classes:

Examples of OutputStreamWriter and InputStreamReader are as follows:

 Packagecom.guigu.shen.StreamTest;ImportJava.io.BufferedReader;ImportJava.io.BufferedWriter;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;ImportJava.io.InputStreamReader;ImportJava.io.OutputStreamWriter; Public classStreamtest { Public Static voidMain (string[] args)throwsException {//Node StreamFileOutputStream fos=NewFileOutputStream ("file.txt"); OutputStreamWriter OS=Newoutputstreamwriter (FOS);//added buffering functionBufferedWriter bufferedwriter=Newbufferedwriter (OS);//Write FileBufferedwriter.write ("Aaaaaaaaaaaaaaaaa"); Bufferedwriter.write ("\ n"); Bufferedwriter.write ("BBBBBBBBBBBBBBB"); Bufferedwriter.close (); /** Read from the file function*///Node StreamFileInputStream fis=NewFileInputStream ("file.txt"); InputStreamReader ISR=NewInputStreamReader (FIS);//Decoration ModeBufferedReader br=NewBufferedReader (ISR);//read every line.String str=Br.readline ();  while(NULL!=str) {System.out.println (str); STR=Br.readline (); }br.close ();}}

Introduce FileWriter. Take a look at an example: read a string into a file:

07JavaIO Explanation of character stream

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.