用户工具


按行获取文件

    public static List<String> readLines(String path) {
        try {
            File file = new File(path);//Text文件
            BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
            List<String> lines = new ArrayList<>();
            String line;
            while ((line = br.readLine()) != null) {//使用readLine方法,一次读一行
                lines.add(line);
            }
            br.close();
            return lines;
        }catch (Exception e){
            return Collections.emptyList();
        }
    }