首先将pay-finish的文件转成txt可阅读然后合并成一起
这里用到shift+右键打开命令行 输入type *.txt>res产生一个新文件然后加入.txt即可
然后用java代码读取文件,并输出指定cash的个数,源代码如下
import java.io.*;
public class demo {
public static int count(String filename, String target)
throws FileNotFoundException, IOException {
FileReader fr = new FileReader(filename);
BufferedReader br = new BufferedReader(fr);
StringBuilder strb = new StringBuilder();
while (true) {
String line = br.readLine();
if (line == null) {
break;
}
strb.append(line);
}
String result = strb.toString();
int count = 0;
int index = 0;
while (true) {
index = result.indexOf(target, index + 1);
if (index > 0) {
count++;
} else {
break;
}
}
br.close();
return count;
}
public static void main(String[] args) {
try {
System.out.println(count("D:\\下载\\题目2附件\\data\\res.txt", "cash"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
运行截图如下