Java IO reads the data in the TXT file using the Java input and output stream, and then writes to another file after stitching

Source: Internet
Author: User

1  PackageCom.sxd.test.util;2 3 ImportJava.io.BufferedReader;4 ImportJava.io.BufferedWriter;5 ImportJava.io.File;6 ImportJava.io.FileInputStream;7 ImportJava.io.FileOutputStream;8 Importjava.io.IOException;9 ImportJava.io.InputStreamReader;Ten ImportJava.io.OutputStreamWriter; One  A Importorg.junit.Test; -  -  Public classCreateinsert { the  - @Test -      Public voidTest ()throwsioexception{ -          +         //1. Reading files -File File =NewFile ("D:/new4.txt"); +InputStreamReader Read =NewInputStreamReader (NewFileInputStream (file), "Utf-8");//considering the encoding format ABufferedReader bu =NewBufferedReader (read); at         //2. Stitching Strings -String Linetext =NULL; -String insert = "INSERT into [report]. [dbo]. [Process] ([Bgid]) VALUES (' "; -String insert2 = "');"; -         //3. Write while reading -OutputStreamWriter out =NewOutputStreamWriter (NewFileOutputStream (NewFile ("d:/write. txt"))); inBufferedWriter WR =NewBufferedWriter (out); -          to          while((Linetext = Bu.readline ())! =NULL){ +System.out.println (insert+linetext+insert2); -Wr.write (insert+linetext+insert2+ "\ r \ n"); the         } * read.close (); $ wr.close ();Panax Notoginseng     } -}
View Code

Java IO reads the data in the TXT file using the Java input and output stream, and then writes to another file after stitching

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.