字节转字符 OutputStreamWriter

package cn.lideng.demo4;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
//字节转字符
public class OutputStreamWriterDemo {
    public static void main(String[] args) {
        writeUTF();
    }
    public static void writeUTF(){
        try {
            //字节
            FileOutputStream fos=new FileOutputStream("d:\\t.txt");
            //字符
            OutputStreamWriter os=new OutputStreamWriter(fos,"utf-8");
            os.write("您好");
            os.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }

}

 

posted @ 2019-03-25 20:10  芯-觞  阅读(310)  评论(0编辑  收藏  举报