public static void getFiles(String filePath) throws SQLException, IOException { File root = new File(filePath); File[] files = root.listFiles(); for (File file : files) { if (file.isDirectory()) { getFiles(file.getAbsolutePath()); filelist.add(file.getAbsolutePath()); } else { String filepath = file.getAbsolutePath(); String weibo_query = ""; InputStreamReader isr = new InputStreamReader( new FileInputStream(filepath), "utf-8"); BufferedReader buffer = new BufferedReader(isr); String string_line = buffer.readLine(); String Title = ""; String Author = ""; String Author_Address = ""; String Journal = ""; String Year = ""; String Issue = ""; String Keywords = ""; String Abstract = ""; String ISBN_ISSN = ""; String Notes = ""; while (string_line != null) { if (string_line == "") string_line = buffer.readLine(); else { if (string_line.indexOf("{Database Provider}") != -1) { String table = "journalismscience"; String sql_insert = "Insert into " + table + " set Title =\'" + Title + "\'" + "," + "Author=\'" + Author + "\'," + "Author_Address=\'" + Author_Address + "\'," + "Journal=\'" + Journal + "\'," + "Year=\'" + Year + "\'," + "Issue=\'" + Issue + "\'," + "Keywords=\'" + Keywords + "\'," + "Abstract=\'" + Abstract + "\'," + "ISBN_ISSN=\'" + ISBN_ISSN + "\'," + "Notes=\'" + Notes + "\'" + ";"; // System.out.println(sql_insert); sql_set.add(sql_insert); // 清除缓存区,写入一条记录至数据库 Title = ""; Author = ""; Author_Address = ""; Journal = ""; Year = ""; Issue = ""; Keywords = ""; Abstract = ""; ISBN_ISSN = ""; Notes = ""; string_line = buffer.readLine(); } else { if (string_line.indexOf("{Title}") != -1) Title = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim().replace("\"", "").replace("\'", "");; if (string_line.indexOf("{Author}") != -1) Author = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim(); if (string_line.indexOf("{Author Address}") != -1) Author_Address = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim(); if (string_line.indexOf("{Journal}") != -1) Journal = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim(); if (string_line.indexOf("{Year}") != -1) Year = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim(); if (string_line.indexOf("{Issue}") != -1) Issue = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim(); if (string_line.indexOf("{Keywords}") != -1) Keywords = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim().replace("\"", "").replace("\'", ""); if (string_line.indexOf("{Abstract}") != -1) Abstract = string_line .substring( string_line.indexOf(":") + 1, string_line.length()).trim().replace("\"", "").replace("\'", ""); if (string_line.indexOf("{ISBN/ISSN}") != -1) ISBN_ISSN = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim(); if (string_line.indexOf("{Notes}") != -1) Notes = string_line.substring( string_line.indexOf(":") + 1, string_line.length()).trim(); string_line = buffer.readLine(); } }