其他分享
首页 > 其他分享> > 演示使用InputStreamReader和OutputStreamWriter

演示使用InputStreamReader和OutputStreamWriter

作者:互联网

package com.io.writer;

import java.io.*;

/**
 * 演示使用OutputStreamWriter
 * 将字节流FileOutputStream转成字符流OutputStreamWriter,指定编码gbk/utf-8
 */
public class OutputStreamWriter_ {
    public static void main(String[] args) throws IOException {
        String filePath="d:\\cyy.txt";
        String charSet="gbk";
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(filePath),charSet);
        osw.write("hi,沐晴");
        osw.close();
        System.out.println("按照"+charSet+"保存文件成功");



    }
}

 


 

 

 

 

 

标签:OutputStreamWriter,String,gbk,io,FileInputStream,演示,InputStreamReader
来源: https://www.cnblogs.com/cyy9310/p/16220739.html