zoukankan      html  css  js  c++  java
  • [Java] 过滤流BufferedInputStream和BufferedOutputStream

     1 package test.stream;
     2 
     3 import java.io.BufferedInputStream;
     4 import java.io.BufferedOutputStream;
     5 import java.io.FileInputStream;
     6 import java.io.FileNotFoundException;
     7 import java.io.FileOutputStream;
     8 import java.io.IOException;
     9 import java.util.Date;
    10 
    11 /**
    12  * 过滤流,需要使用已经存在的节点流来构造,提供带缓冲的读写,提高了读写的效率。
    13  * @author Frost.Yen
    14  * @E-mail 871979853@qq.com
    15  * @date 2016年4月13日
    16  */
    17 public class TestBufferedSteam01 {
    18     public static void main(String[] args) {
    19         long startTime = new Date().getTime();
    20         FileInputStream fis = null;
    21         BufferedInputStream bis = null;
    22         BufferedOutputStream bos = null;
    23         try {
    24             fis = new FileInputStream("D:\FrostYen\software\Adobe\FlashBuilder_4_7_LS10.exe");
    25             bis = new BufferedInputStream(fis);
    26             bos = new BufferedOutputStream(new FileOutputStream("E:\JAVA\Examples\To Learn\src\test\stream\c.exe"));
    27             byte[] buf = new byte[1024];
    28             int len = 0;
    29             while((len = bis.read(buf))>=0){
    30                 bos.write(buf, 0, len);
    31             }
    32             //bos.flush();当关闭流 的时候自动flush
    33         } catch (FileNotFoundException e) {
    34             e.printStackTrace();
    35         } catch (IOException e) {
    36             e.printStackTrace();
    37         }finally {
    38             //当关闭流 的时候自动flush
    39             if(bis!=null)
    40                 try {
    41                     bis.close();
    42                 } catch (IOException e) {
    43                     e.printStackTrace();
    44                 }
    45             if(bos!=null)
    46                 try {
    47                     bos.close();
    48                 } catch (IOException e) {
    49                     e.printStackTrace();
    50                 }
    51         }
    52         
    53         long endTime = new Date().getTime();
    54         //拷贝所耗时间,测试性能
    55         System.out.println((endTime-startTime)/1000);
    56     }
    57 }
  • 相关阅读:
    基于libevent的TLS单向认证CS通信验证
    ubuntu按照时间顺序列出apt安装的程序
    网页识别语音插件annyang可以实现识别中文
    微信小程序图片和签名
    linux run/media/wang/centos_磁盘爆满
    一个页面实现增删改查
    查某关键字在数据库中的哪个位置
    ADO.NET五大对象
    怎样获取当前时间
    string与stringbuilder的区别
  • 原文地址:https://www.cnblogs.com/frost-yen/p/5386894.html
Copyright © 2011-2022 走看看