按行读取目录下的所有文件
File file = new File("E:\\8"); File[] files = file.listFiles(); for(File f:files){ BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(f)); String tempString = null; int line = 1; while ((tempString = reader.readLine()) != null) { if(tempString.split("\001").length!=8){ System.out.println(f.getName()+"line " + line + ": " + tempString); } line++; } reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } }
写文件