java 读写文件内容

按行读取目录下的所有文件

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("01").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) {
                    }
                }
            }
        }

写文件

原文地址:https://www.cnblogs.com/huanhuanang/p/7325771.html