------解决方案-------------------- String类的indexOf递归遍历就可以实现 我觉得 不过效率就不是很好了
------解决方案-------------------- public int findNumOfStringInFile(String filePath,String str)throws Exception{ BufferReader br = new BufferReader(new FileReader(new File(filePath))); String line = null; int num = 0; while(line=br.readLine()!=null){ String[] s = line.split(str); if(s.length()>1) num+=s.length-1; } return num; }
------解决方案--------------------
------解决方案-------------------- 不会写
------解决方案-------------------- BufferedReader in = new BufferedReader(new FileReader("c:\\test.txt")); String s = ""; int num = 0; while ((s = in.readLine()) != null) { if (line.indexOf("zhuobin") > 0) ++num; }