package com.study02;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* 文件字节输出流
* 1.创建源
* 2.选择流
* 3.操作(写出内容)
* 4.释放资源
* @author Administrator
*
*/
public class IOtest04 {
public static void main(String[] args) {
File src = new File("aaa.txt");
OutputStream os = null;
try {
os = new FileOutputStream(src,true);//true:在原来的基础上写入;false:清空原来的数据,重新写入
String msg = new String("IO is so easy!");
byte[] datas = msg.getBytes();//字符串-->字节数组(编码)
os.write(datas,0,datas.length);
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (os!=null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}