File creation in Java

Source: Internet
Author: User

1  PackageCom.xia;2 ImportJava.io.*;3  Public classTest2 {4 5      Public Static voidMain (string[] args) {6         7         //output Stream8         9         Try {TenFileOutputStream fos =NewFileOutputStream ("D:\\213.txt",true);//true to allow append writes One              AString str = "\ n Good afternoon!" The weather is very good! ";//\ n "Escape character" -              -String str2 = "\ n a good mood"; the              -Fos.write (Str.getbytes ());//Overwrite Write -              - fos.close (); +              -FileInputStream FIS =NewFileInputStream ("D:\\213.txt"); +              A             byte[] B =New byte[2048]; at              -             inti =Fis.read (b); -              -String str1 =NewString (b, 0, i); -              -SYSTEM.OUT.PRINTLN ("Read content =" +str1); in              - fis.close (); to              +}Catch(Exception e) { -              the e.printstacktrace (); *         } $         Panax Notoginseng          -     } the  +}

FileOutputStream fos = new FileOutputStream ("D:\\213.txt", true);

Fos.write (Str.getbytes ());

Byte[] B = new byte[2048];

int i = Fis.read (b);

String str1 = new String (b, 0, I);

SYSTEM.OUT.PRINTLN ("Read content =" + str1);

Fis.close ();

1  PackageCom.xia;2 3 ImportJava.io.*;4 5  Public classTest3 {6 7      Public Static voidMain (string[] args) {8         9         Try {Ten              OneFileReader FR =NewFileReader ("D:\\213.txt"); A              -             Char[] c=New Char[2048]; -              the             inti =Fr.read (c); -              -String str =NewString (c,0, i); -              +SYSTEM.OUT.PRINTLN ("Read content =" +str); -              + fr.close (); A              at         //Write -              -FileWriter FW =NewFileWriter ("D:\\213.txt",true); -              -Fw.write ("\ n New Additions"); -              in fw.close (); -              to}Catch(Exception e) { +              - e.printstacktrace (); the         } *     } $}

File creation in Java

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.