import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class IO输出流 {
public static void main(String[] args) {
File f = new File("a2.txt");
OutputStream os = null;
try {
os = new FileOutputStream(f);
// os = new FileOutputStream(f,true); // 在文件后面追加内容
// os = new FileOutputStream(f,false); // 删除之前的内容,再加上新的内容
String s = "IO is so easy!!!";
byte[] msg = s.getBytes();
int len = msg.length;
os.write(msg,0,len);
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(os != null)
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}