JAVA写入大文件DEMO

    /**
     * 读取filePath的文件
     * @param filePath    文件的路径
     * @return     List集合       文件中一行一行的数据
     */
    public static List<String > readToString(String filePath)
    {
        List<String > olist = new ArrayList<String>();
        File file = new File(filePath);
        Long filelength = file.length(); // 获取文件长度
        byte[] filecontent = new byte[filelength.intValue()];
        try{
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();
        } catch (Exception e){
            e.printStackTrace();
        }

        olist = Splitter.on("\n").trimResults().splitToList(new String(filecontent));

        return olist;// 返回文件内容,默认编码
    }

猜你喜欢

转载自www.cnblogs.com/java-h/p/10583794.html