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

BufferedInputStream/BufferedOutputStream复制文件

时间:2016-07-01 15:56:55      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

public class Test{

public static void main(String[] args) throws IOException{
FileInputStream in = null;
BufferedInputStream bis =null;
FileOutputStream out =null;
BufferedOutputStream bos =null;
try {
in=new FileInputStream("c:/123/666.doc");
bis=new BufferedInputStream(in);

out=new FileOutputStream("c:/123/999.doc");
bos = new BufferedOutputStream(out);
int len =0;
byte[] buffer = new byte[1024];
while((len=bis.read(buffer))!=-1){
bos.write(buffer, 0, len);
// bos.write(buffer);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{

bos.flush();    //清空缓存写入数据
bos.close();   //一定要关闭流否则文档打开不了
out.close();
bis.close();
in.close();
}

}

BufferedInputStream/BufferedOutputStream复制文件

标签:

原文地址:http://www.cnblogs.com/chenweichu/p/5633099.html

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