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();
}
}