Java Fundamentals Hardening IO Flow Note 18:fileoutputstream writing data

Source: Internet
Author: User

1. Create a byte output stream object and do a few things:

(1) Call system function to create file
(2) Create Fos object
(3) Point the Fos object to this file

2. code example:

1  PackageCom.himi.fileoutputstream;2 3 ImportJava.io.File;4 Importjava.io.FileNotFoundException;5 ImportJava.io.FileOutputStream;6 Importjava.io.IOException;7 8 /*9 * Create file Fos.txt, write string: Hello WorldTen  *  One * Operation flow of the output of the byte stream: A * A: Create byte output stream object - * B: Write Data - * C: Release Resources the  */ -  -  Public classFileOutputStreamDemo1 { -  +      Public Static voidMain (string[] args)throwsIOException { -         //fileoutputstream (file file) + //File File = new file ("Fos.txt"); A //FileOutputStream fos = new FileOutputStream (file); at          -         //fileoutputstream (String filename) -         /** - * Create a byte output stream object to do a few things: - * A: Call system function to create file - * B: Create Fos object in * C: Point the Fos object to this file -          */ toFileOutputStream FOS1 =NewFileOutputStream ("Fos.txt"); +          -         //Write Data theString str =NewString ("Hello,world"); *         byte[] bytes =str.getbytes (); $ fos1.write (bytes);Panax Notoginseng         //frees up resources to make stream objects garbage so that they can be reclaimed by the garbage collector - fos1.close (); the  +     } A  the}

The output results are as follows:

Java Fundamentals Hardening IO Flow Note 18:fileoutputstream writing data

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.