您的位置:首页 > 其它

23.IO学习——字节流(2)——图片复制…

2015-08-02 12:58 337 查看
字节复制图片重点:

4.复制图片(重点)

 

  需求:

    
1)即有读又有写

    
2)还是非文本数据

    
使用到了字节流中用于操作文件的对象。

  实现:

   
 

 //复制图片

 //1.明确数据的来源

 FileInputStream fis=new
FileInputStream("title.png");

 FileOutputStream fos=new
FileOutputStream("tt.png");

 //2.自定义缓冲区

 byte[] buf=new byte[1024];

 int len=0;

 while ((len=fis.read(buf))!=-1)

 {

  fos.write(buf,0,len);

 }

 fos.close();

 fis.close();

5.缓冲区

  BufferedInputStream

  BufferedOutputStream

  示例:复制图片

              
//缓冲区(速度快)

  FileInputStream fis=new
FileInputStream("title.png");

  FileOutputStream fos=new
FileOutputStream("ttt.png");

    

  BufferedInputStream bfis=new
BufferedInputStream(fis);

  BufferedOutputStream bfos=new
BufferedOutputStream(fos);

  

   int len=0;

  while
((len=bfis.read())!=-1)

  {

   bfos.write(len);

  }

  bfis.close();

  bfos.close();

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: