Go: Java reads txt file and writes TXT file

Source: Internet
Author: User

1  Packageedu.thu.keyword.test;2 3 ImportJava.io.File;4 ImportJava.io.InputStreamReader;5 ImportJava.io.BufferedReader;6 ImportJava.io.BufferedWriter;7 ImportJava.io.FileInputStream;8 ImportJava.io.FileWriter;9 Ten  Public classCin_txt { One     Static voidMain (String args[]) { A         Try{//prevents file creation or read failures, catches errors with catch and prints, or can throw -  -             /*read in TXT file*/ theString pathname = "D:\\twitter\\13_9_6\\dataset\\en\\input.txt";//absolute or relative path, this is an absolute path, and a relative path is shown when writing to a file -File filename =NewFile (pathname);//the input to read the above path. TXT file -InputStreamReader reader =NewInputStreamReader ( -                     NewFileInputStream (filename));//Create an input stream object reader +BufferedReader br =NewBufferedReader (reader);//create an object that turns the contents of a file into a language that the computer can read -String line = ""; +line =br.readline (); A              while(Line! =NULL) { atline = Br.readline ();//read one row of data at a time -             } -  -             /*Write TXT file*/ -File Writename =NewFile (". \\result\\en\\output.txt");//relative path, if not, to create a new output. TXT file -Writename.createnewfile ();//Create a new file inBufferedWriter out =NewBufferedWriter (NewFileWriter (Writename)); -Out.write ("I'll write the file \ r \ n");//\ r \ n is the line break toOut.flush ();//press the buffer contents into the file +Out.close ();//Finally, remember to close the file -  the}Catch(Exception e) { * e.printstacktrace (); $         }Panax Notoginseng     } -}

Transferred from: http://blog.csdn.net/monkeyduck/article/details/11525771

Go: Java reads txt file and writes TXT file

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.