米字键

博客园 首页 新随笔 联系 订阅 管理



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 (Exception e) {

 

           e.printStackTrace();


        }finally{


                if(bos!=null){


                      try {


                        bos.close();

 


                } catch (IOException e) {


       
                    e.printStackTrace();


                }
            }
        }

    }

}

posted on 2019-03-26 17:00  米字键  阅读(135)  评论(0编辑  收藏  举报