JAVA获取txt文件的所有行
1、获取txt文件的所有行
/**
* 获取txt的所有行
* @author xxx
* @date 2023/2/2 16:09
* @param file
* @return List<String>
*/
public static List<String> getAllLineListByTxt(File file) throws IOException {
List<String> readAllLines = null;
try {
readAllLines = Files.readAllLines(Paths.get(file.getCanonicalPath()), Charset.forName("GBK"));
} catch (Exception e) {
e.printStackTrace();
readAllLines = Files.readAllLines(Paths.get(file.getCanonicalPath()),Charset.forName("UTF-8"));
}
return readAllLines;
}

浙公网安备 33010602011771号