public class FindStringInTxt {
String encoding = "UTF-8";
public static void main(String[] args) throws IOException {
findStringInFile("C://1.TXT");
}
public static void findStringInFile(String path) throws IOException{
File file = new File(path);
InputStreamReader read = new InputStreamReader(new FileInputStream(file),"UTF-8");//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if(line.startsWith("#")){
continue;
}
//指定字符串判断处
if (line.contains("xxyy")) {
System.out.println(line);
}
}
}
}
JAVA 判断某个文件中是否包含指定字符串
最新推荐文章于 2024-04-25 11:14:20 发布