187_IO流_FileOutputStream_文件字节输出流_详解

来源:互联网 发布:b超单上的数据怎么看 编辑:程序博客网 时间:2024/06/06 12:23
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();}    }}}

0 0
原创粉丝点击