这100 个文件照你的说法都在同一个目录下,则得出简单的方法是。1。 通过操作系统命令 windows的dir 或者 linux ls 行命令,把所有文件名列出,并复制到excel 中 2。 利用EXCEL的公式生成 insert into table1 (pathName,fileCOntent) value ('/temp/txt/filename1.txt',LOAD_FILE('/temp/txt/filename1.txt')); 3。 把这100行的命令直接贴到mysql行命令运行。一切OK。
BufferedReader reader = new BufferedReader(new FileReader(productfile));
String name = fname; String path= productfile.getPath(); StringBuffer content = new StringBuffer(); String line = reader.readLine(); while (line != null && !line.equals(Extractor.SEPARATOR)){ content.append(line).append("\r\n"); line = reader.readLine(); } // make the Product object Project p = new Project(); 然后 把这个Project 持久到数据库里,这个你会吗?不会再说 }
2。 利用EXCEL的公式生成 insert into table1 (pathName,fileCOntent) value ('/temp/txt/filename1.txt',LOAD_FILE('/temp/txt/filename1.txt'));
3。 把这100行的命令直接贴到mysql行命令运行。一切OK。
private String path; //存路径
private String content; //存内容
然后
private void traverse(File file) throws Exception {
String [] files = file.list();
for (int i = 151; i < files.length; i++) {
File productfile = new File(file, files[i]);
String fname = productfile.getName();
System.out.println(productfile);
BufferedReader reader = new BufferedReader(new FileReader(productfile));
String name = fname;
String path= productfile.getPath();
StringBuffer content = new StringBuffer();
String line = reader.readLine();
while (line != null && !line.equals(Extractor.SEPARATOR)){
content.append(line).append("\r\n");
line = reader.readLine();
}
// make the Product object
Project p = new Project();
然后 把这个Project 持久到数据库里,这个你会吗?不会再说
}
ls -l |awk '{print "insert into table1 (pathName,fileCOntent) value (/temp/txt/"$1",LOAD_FILE(/temp/txt/$1)")' >do.sql
mysql dbname<do.sql