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 }
  • 相关阅读:
    (三)mybatis 的使用(入门)
    (二)mybatis框架原理(图解)
    (一)使用 mybatis 的缘由
    (八)Spring 事务管理
    (七)Spring 配置 c3p0 连接池
    (六)Spring 中的 JdbcTemplate
    熔断监控集群(Turbine)
    熔断监控面板(Hystrix Dashboard)
    容错机制和熔断(Hystrix)
    服务消费和负载(Feign)
  • 原文地址:https://www.cnblogs.com/frost-yen/p/5386894.html
Copyright © 2011-2022 走看看