Document structure
Note: The import document character format needs to be converted into utf-8 format and then exported, otherwise the exported data Chinese display garbled.
Java code
1 Packagetest;2 ImportJava.io.BufferedReader;3 ImportJava.io.BufferedWriter;4 ImportJava.io.File;5 ImportJava.io.FileOutputStream;6 ImportJava.io.FileReader;7 ImportJava.io.FileWriter;8 ImportJava.io.InputStream;9 ImportJava.io.OutputStreamWriter;Ten Public classInserttest { One Public Static voidMain (string[] args)throwsexception{ AFileOutputStream Writerstream =NewFileOutputStream ("Result.txt");//sql statement write to data file -BufferedWriter BW =NewBufferedWriter (NewOutputStreamWriter ( -Writerstream, "UTF-8")); thestring[] Filearr =Newstring[]{"Games.txt", "NickLib.txt"};//reading a resource data file -BufferedReader reader =NULL; - for(intK = 0;k <filearr.length;k++){ -File File =NewFile (Filearr[k]); +FileReader re =Newfilereader (file); -Reader =NewBufferedReader (re); +String str =NULL; A while(str = reader.readline ())! =NULL){ atstring[] arr = str.split ("//"); - if(!arr[0].equals ("")){ -String type =NULL; - for(inti = 0; i<arr.length;i++){ -Arr[i] = Arr[i].replaceall ("\\s*", "" "); - } in if(Arr[0].endswith ("JSP")){ -Type = "100"; to } + if(Arr[0].endswith ("Action")){ -Type = "101"; the } *String sout = "INSERT into T_resource (resourcetypeid,url,title) VALUES (" +type+ "," + "'" +arr[0]+ "'" + "," + "'" +arr[1]+ "'" + ");"; $Bw.write (sout+ "\ r \ n");Panax Notoginseng } - the } +Bw.write ("#" +filearr[k]+ "\ r \ n"); A reader.close (); the } + bw.close (); - } $ $}
Java implementation transforms a resource file into a SQL statement into a database