Java byte stream and NLP stream exercises

Source: Internet
Author: User

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 ));}} 

 

 

Related Article

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.