标签:
文档结构
注意事项:导入文档字符格式需转化成utf—8格式再进行导出,否则导出数据中文显示乱码。
java代码
1 package test; 2 import java.io.BufferedReader; 3 import java.io.BufferedWriter; 4 import java.io.File; 5 import java.io.FileOutputStream; 6 import java.io.FileReader; 7 import java.io.FileWriter; 8 import java.io.InputStream; 9 import java.io.OutputStreamWriter; 10 public class InsertTest { 11 public static void main(String[] args) throws Exception{ 12 FileOutputStream writerStream = new FileOutputStream("result.txt");//sql语句写入数据文件 13 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( 14 writerStream, "UTF-8")); 15 String[] fileArr = new String[]{"games.txt","nickLib.txt"};//读取资源数据文件 16 BufferedReader reader = null; 17 for(int k = 0;k <fileArr.length;k++){ 18 File file = new File(fileArr[k]); 19 FileReader re = new FileReader(file); 20 reader = new BufferedReader(re); 21 String str = null; 22 while((str = reader.readLine())!=null){ 23 String[] arr = str.split("//"); 24 if(!arr[0].equals("")){ 25 String type = null; 26 for(int i = 0; i<arr.length;i++){ 27 arr[i] = arr[i].replaceAll("\\s*", ""); 28 } 29 if(arr[0].endsWith("jsp")){ 30 type = "100"; 31 } 32 if(arr[0].endsWith("action")){ 33 type = "101"; 34 } 35 String sout = "insert into t_resource (ResourceTypeId,url,Title) values ("+type+","+"‘"+arr[0]+"‘"+","+"‘"+arr[1]+"‘"+");"; 36 bw.write(sout+"\r\n"); 37 } 38 39 } 40 bw.write("#"+fileArr[k]+"\r\n"); 41 reader.close(); 42 } 43 bw.close(); 44 } 45 46 }
标签:
原文地址:http://www.cnblogs.com/weilantiankong/p/4678633.html