Javaio writing data to a file

Source: Internet
Author: User

Package com. Practice_filewriter;import Java.io.filewriter;import java.io.IOException; Public classJustpractice { Public Static voidMain (string[] args) throws IOException {//The first step is to create an output stream object that can write data to the file, which is the path to write to the file;FileWriter FW =NewFileWriter ("D:\\fw.txt"); //In the second step, the write method of the FW is called, and the data is written to the file;Fw.write (" haha haha haha");//at this point the data is actually written to the temporary file buffer, and did not write to the file you specified,//The third step is to call the flush () method of the FileWriter object to write the data to the specified fileFw.flush (); //Finally, call the Close method to close the output stream, which automatically calls the previous Flush method and writes the buffer data to the destination file .Fw.close (); }}

The write () method of the class reader in the Java.io package, all classes that have the suffix reader inherit these methods:

Javaio writing data to a file

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.