Java implementation transforms a resource file into a SQL statement into a database

Source: Internet
Author: User

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

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.