读取文本

    public static String readText(File file) {
        StringBuilder result = new StringBuilder();
        try (FileReader reader = new FileReader(file);) {
            int count = 0;
            char[] buffer = new char[1024];
            while ((count = reader.read(buffer, 0, buffer.length)) > 0) {
                result.append(new java.lang.String(buffer, 0, count));
                // Arrays.fill(buffer, '\0');
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.toString();
    }

 

posted @ 2020-02-25 19:32  zslm___  阅读(120)  评论(0编辑  收藏  举报