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

  • Post author:
  • Post category:其他


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);
        }
    }



版权声明:本文为J_Jorey原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。