Posted in 面试题 onApril 13, 2016
答:代码如下:
public 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 c = in.read();
if (c != find.charAt(i)) break;
if (i == find.length() – 1) count++;
}
}
}
return count;
}
public 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 c = in.read();
if (c != find.charAt(i)) break;
if (i == find.length() – 1) count++;
}
}
}
return count;
}
写一个方法,输入一个文件名和一个字符串,统计这个字符串在这个文件中出现的次数
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@