package TestIO;
import java.io.*;
public class Test01 {
public static void main(String[] args) {
FileOutputStream fos=null;
try {
fos = new FileOutputStream("d:/test1.txt",true);//以追加的方式写入文件
String str = "hello word";
byte[] bytes =str.getBytes() ;
fos.write(bytes);
String str1 = "\r\n";//换行
fos.write(str1.getBytes());
fos.flush();//推荐最后的时候为了保证数据完全写入硬盘,所以要刷新
} catch (FileNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch(IOException e){
e.printStackTrace();
}finally{
try {
if(fos != null){}
fos.close();
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
}