outputstreamwriter实现写入字符串

TestTransform1.java的源代码如下:

package com.daozhao.io;

import java.io.*;

public class TestTransform1 {
	public static void main(String[] args){
		try{
			OutputStreamWriter osw =new OutputStreamWriter(new FileOutputStream("e:\\4.txt"));
			osw.write("microsoftapplesunhp");
			System.out.println(osw.getEncoding());
			osw.close();
			
			osw=new OutputStreamWriter(new FileOutputStream("e:\\4.txt",true),"ISO8859_1");
			osw.write("helloworld");
			System.out.println(osw.getEncoding());
			osw.close();
		} catch(IOException e){
			System.out.println("未知错误");
			System.exit(-1);
		}
	}
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注