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