BufferedWriter以append方式写入文件,指定编码

public static void writeFile(String fileName, String contents, boolean append) throws IOException {
        try {
            File file = new File(fileName);
            BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(
                            new FileOutputStream(file, append), "GB2312"));
            writer.write(contents);
            writer.flush();
            writer.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
发布了9 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/J_Jorey/article/details/102814850