package com.io.liushuaishuai; /* 构造方法: OutputStreamWriter (OutputStream out) 创建一个使用默认字符编码的OutputStreamWriter 写数据的5种方式: void writer (int c):写一个字符 void writer (char[] cbuf):写一个字符数组 void writer (char[] cbuf,int off,int len):写入字符数组的一部分 void writer (String str):写一个字符串 void writer (String str,int off,int len):写一个字符串的一部分 */ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; public class OutputStreamWriterDemo { public static void main(String[] args) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("myIOstream\fos.txt")); //写数据 char[] a ={'a','b','c','d','e'}; //osw.write(97); // osw.flush();//刷新流 //osw.write(98); //osw.write(a); osw.write(a,4,1); osw.flush(); osw.close(); } }