Byte stream-byte stream
Package Com. CMM. io4; Import Java. Io .* ; Public Class Fileio { /** * @ Param ARGs * @ Author CMM * @ title: fileoutputstream & fileinputstream -- byte stream */ Public Static Void Main (string [] ARGs) Throws Exception { // Todo auto-generated method stub // Outputstream out = NULL; // Out = new fileoutputstream (new file ("F: \ CMMs. txt ")); /* Fileoutputstream */ File F = New File ("F: \ cm.txt" ); Fileoutputstream out = New Fileoutputstream (f); string Str = "CMM welcome to my board htx" ; Out. Write (Str. getbytes ( "Gb2312" ); Out. Close (); /* Fileinputstream */ Fileinputstream in = New Fileinputstream (f ); Byte B [] = New Byte [500 ]; Int Len = 0 ; Len = In. Read (B); in. Close (); system. Out. println ( New String (B, 0 , Len ));}}
Char stream -- cached stream (Cache used)
Package Com. CMM. io4; Import Java. Io .* ; Public Class Rwtest { /** * @ Param ARGs * @ Author CMM * @ tilte: Reader/writer -- char stream */ Public Static Void Main (string [] ARGs)Throws Exception {file F = New File ("F: \ cm.txt" ); /* Write output char stream */ // Writer out = NULL; Filewriter out = New Filewriter (f); string Str = "So wat are you do now? " ; Out. Write (STR); Out. Flush (); Out. Close (); /* Read input char stream */ // Reader in = NULL; Filereader in = New Filereader (f ); Char Ch [] = New Char [500 ]; Int Len = 0 ; Len =In. Read (CH); in. Close (); system. Out. println ( New String (CH, 0 , Len ));}}