package xinhuiji_day07;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class CopyOfTestFileOutPutStream {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String str = File.separator;
//String path = File.separator+"home"+File.separator+"han"+File.separator+"FileOutPutStream.txt";
String path = str+"home"+str+"han"+str+"FileOutPutStream.txt";
File file = new File(path);
//
// try {
// file.createNewFile();
// } catch (Exception e) {
// // TODO: handle exception
// }
OutputStream out = null;
//out = new FileOutputStream(file);//这种构造方法创建的对象,在每次调用的时候都会覆盖掉原来的数据
out = new FileOutputStream(file, true);//true 表示每次向file中写入数据的时候并不覆盖掉原来的数据
//而是在之前的文本后面继续添加新的内容
String content = "my name is siashan!";
byte[] bytes = content.getBytes();
//out.write(bytes); //接受一个byte[]
for(int i = 0;i<bytes.length;i++){
out.write(bytes[i]); //接受一个字节
}
out.close();
}
}