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

带缓存的输入流输出流

时间:2017-01-16 13:09:21      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:bsp   输入流   input   []   file   int   stat   ring   users   

 1 import java.io.BufferedInputStream;
 2 import java.io.BufferedOutputStream;
 3 import java.io.FileInputStream;
 4 import java.io.FileNotFoundException;
 5 import java.io.FileOutputStream;
 6 import java.io.IOException;
 7 
 8 public class TestBufferedStream {
 9     public static void main(String[] args) {
10         BufferedInputStream bis = null;
11         BufferedOutputStream bos = null;
12         
13         try {
14             bis = new BufferedInputStream(new FileInputStream("D:\\MY文档\\pic\\云纱.jpg"));
15             bos = new BufferedOutputStream(new FileOutputStream("C:/Users/Polly/java/天河菱纱.jpg"));
16             byte[] buf = new byte[1024];
17             int len = 0;
18             while((len=bis.read(buf))>=0){
19                 bos.write(buf,0,len);
20             }
21             //需要对缓存流进行刷新,或者用finally结束缓存流;
22             //bos.flush();
23             
24         } catch (FileNotFoundException e) {
25             e.printStackTrace();
26         } catch (IOException e) {
27             e.printStackTrace();
28         } finally{
29             try {
30                 if (bis!=null) bis.close();
31             } catch (IOException e) {
32                 e.printStackTrace();
33             }
34             try {
35                 if (bos!=null) bos.close();
36             } catch (IOException e) {
37                 e.printStackTrace();
38             }
39         }
40         
41     }
42 
43 }

 

带缓存的输入流输出流

标签:bsp   输入流   input   []   file   int   stat   ring   users   

原文地址:http://www.cnblogs.com/lol-ashe/p/6289167.html

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