IO流——转换流之BufferedWriter

package com.io.ioDemo;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * 字节转字符输出
 * @author Administrator
 *
 */
public class OutputStreamWriterDemo {
	public static void main(String[] args) {
		BufferedWriter bw = null;
		try {
			//1.声明方式2.主要作用:编码
			bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("c:\\osw.txt")),"utf-8"));
			bw.write("123");
			bw.write("你好");
			bw.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				bw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

你可能感兴趣的:(java)