File file = new File("E:\\test\\hello.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
List<String> list = new ArrayList<>();
String lineTxt = null;
/*while ((lineTxt = br.readLine()) != null){
if (lineTxt.contains("10014")){
list.add(lineTxt);
}
}*/
while ((lineTxt = br.readLine()) != null){
if (lineTxt.startsWith("m",5)){
list.add(lineTxt);
}
if (list.size() == 5){
break;
}
}
for (String s : list) {
System.out.println(s);
}
if (br != null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
io 遍历文本、查询指定内容
于 2021-08-13 15:41:54 首次发布