码迷,mamicode.com
首页 > 其他好文 > 详细

5、过滤流

时间:2015-12-03 21:16:14      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

 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 }

 

5、过滤流

标签:

原文地址:http://www.cnblogs.com/Akke/p/5017480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!