`
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class TestController {
public static void main(String[] args) {
try {
List<String> list = gtFilterList(new BufferedReader(new FileReader("C:\\Users\\WUKONG\\Desktop\\log.txt")));
if (list != null){
for (String string : list){
System.out.println(string);
}
}else{
System.out.println("文件读取失败!");
}
} catch (FileNotFoundException e) {
System.out.println("文件不存在!");
}
}
public static List<String> gtFilterList(BufferedReader br){
if (br != null) {
return br.lines().filter(line -> line.contains("这")).collect(Collectors.toList());
}
return null;
}
}
`
标签:java,读取,System,按行,io,import,null,out From: https://www.cnblogs.com/dawndefend/p/18453601