java实现将资源文件转化成sql语句导入数据库

时间:2021-09-10 19:56:56

文档结构

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPwAAAC0CAIAAAA/wtYxAAATEUlEQVR4nO2db3BU5b3H943v88KZllfae63NyFy9UvWmW81l2pGg/RPunclMmKlTxuhWem9HULwESUoIDcYsjiskSGsTgreki6KNUtekyoXgEKBl2iBBctkqSQMSNtl0TUhyNov3uS/Ov+fvOWf/5ew5z+8zzzC7Z5/nnGcnn314zub55gkgAJCMwBJco/zxvUtwFQBwCEgPSEdhpD/31hajsK96TfpYKBCKIYTikWAgGIm73R2g0BRA+qHDW8in9VQFkB4oKXKXvmP7ix3bX+zY3rp4vWvxetf85b1T58LjA43/++7Gju2tCKHqnx9Sa3pVeivikaB9JaA0sZH+2LFjra2t3Jde3PpSyyun0Rcn+AVzHaQHSgor6Y8ePbp8+fI777xTVOGZjXvQ5BF+QejNExfLH99b/vje/X84x2utehMLBQL6JCIWCmgYs4p4JKgfMxwzq5kHcQnNx04uwT1iTG+0c5LdwDoA0x8PIpReNb62ttZC+rqf/BJd/Y2w2KCKhKtMqB6KccfTWAg3LRYKMIJS0lOfFtJS3kVZ6TndgJHew/ClN4xfu3athfQIocSZ/WMHaxJn9iOE1j3Rte6JTrX8+InOdU92/lh9/GTnuic6maakN/jwbY6h6lFMVNxS/CRWI72orcVFKdeZboD0XoYjPW68rfRjB2vQzfNjB2sQQu+MfSkq//aj/2aa2hlJ1jSFpKUPRuJ5SM+5KGd6Q3cDpPcyHOlbW1vvxNi5c6eoceL4LmWkaU15QBlpShx/CSF06JP0oU+UQ5+ksaI8XBPltaa8MWYq6hNNuwgtMjO9MSXUDscjwQBXeuISsYj+Pwl9Ud70hukGSO9h8vqefuxgjSG9Oth3Dc50nZzpGpzpPDnTNTjTNTjzrTWHBa0Zb6xvWvkzIfOo0ToYCvFHeuIS+H8L1CHOSM92Q2sHN7IeJHfpx47UJ4+vU0aaPu6sVEaaksfW/e1I/e7Y1O73JnfH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GeicbwYL0gI4XM7IcF7PZCJbaZZaRHrKwfseLGVluppv+w0zs32oyapG7zBJ/BorjNWRhfQdkZAHpgIwsIB2QkQWkA5YWA9IB0gPSAdID0gHSA9Lx/xrTsb1ZrndjAAAAAElFTkSuQmCC" alt="" />

注意事项:导入文档字符格式需转化成utf—8格式再进行导出,否则导出数据中文显示乱码。

java代码

 package test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStreamWriter;
public class InsertTest {
public static void main(String[] args) throws Exception{
FileOutputStream writerStream = new FileOutputStream("result.txt");//sql语句写入数据文件
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
writerStream, "UTF-8"));
String[] fileArr = new String[]{"games.txt","nickLib.txt"};//读取资源数据文件
BufferedReader reader = null;
for(int k = 0;k <fileArr.length;k++){
File file = new File(fileArr[k]);
FileReader re = new FileReader(file);
reader = new BufferedReader(re);
String str = null;
while((str = reader.readLine())!=null){
String[] arr = str.split("//");
if(!arr[0].equals("")){
String type = null;
for(int i = 0; i<arr.length;i++){
arr[i] = arr[i].replaceAll("\\s*", "");
}
if(arr[0].endsWith("jsp")){
type = "100";
}
if(arr[0].endsWith("action")){
type = "101";
}
String sout = "insert into t_resource (ResourceTypeId,url,Title) values ("+type+","+"'"+arr[0]+"'"+","+"'"+arr[1]+"'"+");";
bw.write(sout+"\r\n");
} }
bw.write("#"+fileArr[k]+"\r\n");
reader.close();
}
bw.close();
} }