您的位置:首页 > 其它

写一个方法,输入一个文件名和一个字符串,统计这个字符串在这个文件中出 现的次数。

2015-06-09 20:36 483 查看
<span style="font-size:18px;">ublic int countWords(String file, String find) throws Exception
{
int count = 0;
Reader in = new FileReader(file);
int c;
while ((c = in.read()) != -1) {
while (c == find.charAt(0)) {
for (int i = 1; i < find.length(); i++) {
c = in.read();
if (c != find.charAt(i)) break;
if (i == find.length() - 1) count++;
}
}
}
return count;
}
</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: