首页 > 其他分享 >获取txt文件的所有行

获取txt文件的所有行

时间:2023-02-02 16:22:45浏览次数:34  
标签:文件 Paths List 获取 readAllLines file 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;
    }

  

标签:文件,Paths,List,获取,readAllLines,file,txt
From: https://www.cnblogs.com/wwssgg/p/17086396.html

相关文章