The conversion of Java learning character stream and byte stream

Source: Internet
Author: User

1  PackageCom.io;2 3 ImportJava.io.File;4 ImportJava.io.FileInputStream;5 Importjava.io.FileNotFoundException;6 Importjava.io.IOException;7 ImportJava.io.InputStream;8 ImportJava.io.InputStreamReader;9 /**Ten * Byte stream is read into a character flow One  * @authorGanhang A  * -  */ -  Public classInputstreamreaderdemo { the      Public Static voidMain (string[] args) { -File File =NewFile ("1.txt"); - InputStream in; -         Try { +in =Newfileinputstream (file); -InputStreamReader isr=NewInputStreamReader (in); +             intLen=-1; AStringBuffer sb=NewStringBuffer (); at             Char[]b=New Char[10]; -              while((Len=isr.read (b))!=-1){ -Sb.append (b,0, Len); -             } - isr.close (); - in.close (); in System.out.println (SB); -}Catch(FileNotFoundException e) { to e.printstacktrace (); +}Catch(IOException e) { - e.printstacktrace (); the         } *     } $}
1  PackageCom.io;2 ImportJava.io.File;3 Importjava.io.FileNotFoundException;4 ImportJava.io.FileOutputStream;5 Importjava.io.IOException;6 ImportJava.io.OutputStream;7 ImportJava.io.OutputStreamWriter;8 /**9 * Character flow is byte writeTen  * @authorGanhang One  * A  */ -  Public classOutputstreamwriterdemo { -      Public Static voidMain (string[] args) { theFile file=NewFile ("1.txt"); - OutputStream out; -         Try { -out =NewFileOutputStream (file,true); +OutputStreamWriter osw=NewOutputStreamWriter (out); -String info= "haha haha haha"; + Osw.write (info); A osw.close (); at out.close (); -System.out.println ("Write succeeded!")); -}Catch(FileNotFoundException e) { - e.printstacktrace (); -}Catch(IOException e) { - e.printstacktrace (); in         } -     } to}

The conversion of Java learning character stream and byte stream

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.