按照某种编码格式写入相关数据,实现过程如下:

public class OutputStreamWriter_ {
    public static void main(String[] args) throws IOException {
        String filePath = "E:\\writer.txt";
        String setchar = "UTF-8";
        OutputStreamWriter opw = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(filePath)),setchar);
        opw.write("欢迎来到我的世界~");
        opw.close();
        System.out.println("按照 "+setchar+" 文件写入成功~");
    }
}

你可能感兴趣的:(韩顺平java习题,java,开发语言)