1. 程式人生 > >使用字節緩沖流在文件中寫內容

使用字節緩沖流在文件中寫內容

finally ktr java write pub tput nbsp buffered pan

package text;

import java.io.BufferedOutputStream;

import java.io.FileOutputStream;
import java.io.IOException;

public class Buff2 {


   public static void main(String[] args) {


     BufferedOutputStream bos=null;


     try {


//        使用字節緩沖在文件中寫內容


     bos=new BufferedOutputStream(new FileOutputStream("D:\\IO\\java.txt",true));


//        寫入內容


     bos.write(65);


//      寫入字符串


     byte []b="hello word\r\nhttp".getBytes();


     bos.write(b);


//    截取的內容重一遍


   bos.write(b,1,3);


   } catch (IOException e) {

  e.printStackTrace();


     }finally{


   if(bos!=null){


  try {


     bos.close();


     } catch (IOException e) {


     e.printStackTrace();


}
}
}
}
}

使用字節緩沖流在文件中寫內容