工具箱

来源:互联网 发布:题库系统源码 编辑:程序博客网 时间:2024/04/27 21:19
递归输出文件夹下的所有文件
    public static void listFileName(File file){        File[] files = file.listFiles();        for(File f : files){            if(f.isDirectory()){                listFileName(f);            }            System.out.println(f.getName());        }    }
统计某个单词出现的次数
public static int wordCount(String filePath, String word) throws IOException{        int count = 0;        BufferedReader reader = new BufferedReader(new FileReader(filePath));        String line = "";        while((line = reader.readLine()) != null){            count += ((line.length() - line.replace(word, "").length()) % line.length()) / word.length();        }        reader.close();        return count;    }
0 0