Java按行读取文件工具类

import java.io.*;
import java.util.*;

public class FileReadUtil {
    public static List<String> ReadFile(String file) {
        List<String> list = new ArrayList<>();
        String str;
        try {
            LineNumberReader reader = new LineNumberReader(new FileReader(file));
            while ((str = reader.readLine()) != null) {
                if (!str.isEmpty()) {
                    list.add(str);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }
} 
posted @ 2020-09-07 10:32  林宇风  阅读(703)  评论(0编辑  收藏  举报