您的位置:首页 > 其它

工具箱

2016-07-19 21:27 344 查看
递归输出文件夹下的所有文件

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  工具箱