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