java--text File Write

Source: Internet
Author: User

Writing to a text file

1. Associating read-in files, using reader and FileReader

2. Associating written files, using writer and FileWriter

3. Create a buffered char array for receiving read-through text information

4. Read the text into the buffer array (buff)

5. Output the text information read

6. Write down the Read file

7. Turn off write file stream

8. Turn off Read file stream

 PackageCom.machuang.io.charIO;Importjava.io.FileNotFoundException;ImportJava.io.FileReader;ImportJava.io.FileWriter;Importjava.io.IOException;ImportJava.io.Reader;ImportJava.io.Writer; Public classTextwrite { Public Static voidMain (string[] args) {//Connect with DocumentsReader reader =NULL; Writer writer=NULL; Try{Reader=NewFileReader ("F:/win10/test/a.txt"); Writer=NewFileWriter ("F:/win10/test/acopy.txt",true); //creating a char string buffer array            Char[] Cbuf =New Char[1024]; //Read and write            intLen = 0;  while( -1! = (len =Reader.read (CBUF)))                {Writer.write (CBUF);            Writer.flush (); }        } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } finally {            Try {                if(NULL!=writer)                {Writer.close (); }                if(NULL!=reader)                {Reader.close (); }            } Catch(IOException e) {e.printstacktrace (); }                    }            } //Match main function}

java--text File Write

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.