zoukankan      html  css  js  c++  java
  • 5、过滤流

     1 package Io;
     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 public class BufferedStream_IoTest {
    12     public static void main(String[] args) {
    13         long startTime = new Date().getTime();
    14         FileInputStream fis = null;
    15         FileOutputStream fos = null;
    16         BufferedInputStream bis = null;
    17         BufferedOutputStream bos = null;
    18         try {
    19             fis = new FileInputStream("C:\Users\Samuel\Pictures\Allah Will Listen.png");
    20             bis = new BufferedInputStream(fis);
    21             fos = new FileOutputStream("G:\IoTest\Allah Will Listen.png");
    22             bos = new BufferedOutputStream(fos);
    23             byte[] buf = new byte[1024];
    24             int len = 0;
    25             while ((len = fis.read(buf)) > 0) {
    26                 bos.write(buf, 0, len);
    27             }
    28 
    29         } catch (FileNotFoundException e) {
    30             e.printStackTrace();
    31         } catch (IOException e) {
    32             e.printStackTrace();
    33         } finally {
    34             //当关闭流时会自动flush
    35             if (fis != null)
    36                 try {
    37                     fis.close();
    38                 } catch (IOException e) {
    39                     // TODO Auto-generated catch block
    40                     e.printStackTrace();
    41                 }
    42         }
    43         long endTime = new Date().getTime();
    44         System.out.println("需要"+(endTime-startTime)/1000);
    45     }
    46 }
  • 相关阅读:
    cpu 怎么区分指令与数据,寄存器与内存各自对应什么
    添加省略号
    有关自有属性,原型属性的问题
    实现一个new
    滚动条样式修改
    备忘录实现+具体需求应用备忘录
    Math.random生成指定范围的随机数
    reduce详细用法
    一个搜索上下的功能,用的不多
    svg拖拽rect,line,circle
  • 原文地址:https://www.cnblogs.com/Akke/p/5017480.html
Copyright © 2011-2022 走看看