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

利用文件的输入流输出流实现文件的拷贝

时间:2017-01-16 13:07:22      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:str   print   pre   div   控制台   puts   leo   ack   use   

 1 import java.io.FileInputStream;
 2 import java.io.FileNotFoundException;
 3 import java.io.FileOutputStream;
 4 import java.io.IOException;
 5 /**
 6  * 利用文件的输入流输出流实现文件的拷贝;
 7  * */
 8 public class TestFileOutputStream {
 9     public static void main(String[] args) {
10         FileInputStream fis = null;
11         FileOutputStream fos = null;
12         
13         try {
14             fis = new FileInputStream("D:\\MY文档\\pic\\Polly.jpg");
15             fos = new FileOutputStream("C:/Users/Polly/java/柏莉.jpg");
16             byte[] buf = new byte[1024];
17             int len = 0;
18             while((len=fis.read(buf))>=0){
19                 fos.write(buf, 0, len);
20                 //System.out.write(buf, 0, len);//这是往控制台输出;
21             }
22             
23         } catch (FileNotFoundException e) {
24             e.printStackTrace();
25         } catch (IOException e) {
26             e.printStackTrace();
27         } finally{
28             try {
29                 if(fis!=null) fis.close();
30             } catch (IOException e) {
31                 e.printStackTrace();
32             }
33             try {
34                 if(fos!=null) fos.close();
35             } catch (IOException e) {
36                 e.printStackTrace();
37             }
38         }
39     }
40 }

 

利用文件的输入流输出流实现文件的拷贝

标签:str   print   pre   div   控制台   puts   leo   ack   use   

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

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