带缓冲区的字节流

 1 package com.itheima;
 2 import java.io.BufferedInputStream;
 3 import java.io.BufferedOutputStream;
 4 import java.io.FileInputStream;
 5 import java.io.FileOutputStream;
 6 import java.io.IOException;
 7 public class Test06 {
 8 
 9     /**
10      * 需求:使用带缓冲功能的字节流复制文件。
11      */
12     public static void main(String[] args) {
13         // TODO Auto-generated method stub
14         long start = System.currentTimeMillis();
15         copy();
16         long end = System.currentTimeMillis();
17         System.out.println((end-start)+"毫秒");//查看拷贝用时
18     }
19     //通过字节流的缓冲区复制图片
20     public static void copy() {
21         
22         FileInputStream fis = null;
23         FileOutputStream fos = null;
24         BufferedInputStream bufis = null;
25         BufferedOutputStream bufos = null;
26         try
27         {
28             fis = new FileInputStream("c:\\1.jpg");
29             fos = new FileOutputStream("c:\\copy_1.jpg");
30             bufis = new BufferedInputStream(fis);
31             bufos = new BufferedOutputStream(fos);
32             int by = 0;
33             while ((by=bufis.read())!=-1)
34             {
35                 bufos.write(by);
36             }
37         }
38         catch (IOException e)
39         {
40             throw new RuntimeException("读写失败");
41         }
42         finally
43         {
44             try
45             {
46                 bufis.close();
47                 bufos.close();
48             }
49             catch (IOException e)
50             {
51                 throw new RuntimeException("关闭异常");
52             }
53                 
54         }
55     }
56 }

 

转载于:https://www.cnblogs.com/wtyqer/p/3527718.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值