java如何查看一个文件中是否存在某一个字符串文本如下:

#xxxx
abc dd
#0080
sljdflsjl
上面的这段文本中,#开头的一段不会被查找,要的就是判断是否存在abc dd

可先读文件内容进内存 一次全部读完
再遍历内存中的文件内容
然后 比较 如 “abc dd”.equals( content);
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-13
File f = new File("tmp.txt");
FileInputStream fis = new FileInputStream(f);
Reader bis = new InputStreamReader(fis);
String line = null;
while ((line = reader.readLine()) != null) {
if(line.startsWith("#")){
continue;
}
if (line.contains("abc dd")) {
//do somthing...
}
}本回答被提问者和网友采纳
相似回答