The bytes of the "Java" IO stream are streamed to a character stream: Java.io.OutputStreamWriter and Java.io.InputStreamReader

Source: Internet
Author: User

1  Packagefile operation;2 3 ImportJava.io.File;4 ImportJava.io.FileOutputStream;5 Importjava.io.IOException;6 ImportJava.io.OutputStream;7 ImportJava.io.OutputStreamWriter;8 9  Public classTestoutputstreamwriter {Ten      Public Static voidMain (string[] args)throwsIOException { OneFile file=NewFile ("D:" +file.separator+ "Test.txt"); AOutputStream out =NewFileOutputStream (file);//If the file does not exist, it will be created automatically -         //the byte stream is converted to a character stream. The contents of the file are essentially in the form of a byte operation in the operating system, which requires implicit conversion in the buffer when processing Chinese -OutputStreamWriter outputstreamwriter=NewOutputStreamWriter (out); theString str= "welcom! China"; - outputstreamwriter.write (str); - //Outputstreamwriter.flush ();//content is written into the file after the flush () or close () operation - outputstreamwriter.close (); +     } -}
OutputStreamWriter

1  Packagefile operation;2 3 ImportJava.io.File;4 ImportJava.io.FileInputStream;5 Importjava.io.IOException;6 ImportJava.io.InputStream;7 ImportJava.io.InputStreamReader;8 9  Public classTestinputstreamreader {Ten      Public Static voidMain (string[] args)throwsIOException { OneFile file=NewFile ("D:" +file.separator+ "com" +file.separator+ "test.txt"); A         Char[] chars=New Char[1024]; -         if(File.exists ()) { - //file.getparentfile (). Mkdirs ();//It is recommended to use mkdirs instead of Mkdir,mkdirs to create a single-level catalog and to create multilevel catalogs, mkdir can only create single-level catalogs the //file.createnewfile (); -InputStream in=Newfileinputstream (file); -InputStreamReader inputstreamreader=NewInputStreamReader (in); -             intlen=Inputstreamreader.read (chars); +System.out.println ("*" +NewString (Chars,0,len) + "*"); - inputstreamreader.close (); +         } A     } at}
InputStreamReader

The bytes of the "Java" IO stream are streamed to a character stream: Java.io.OutputStreamWriter and Java.io.InputStreamReader

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.