首页 > 编程语言 > 详细

Java复制文件

时间:2018-04-12 12:09:54      阅读:176      评论:0      收藏:0      [点我收藏+]
 1  public void copyFile(File fromFile,File toFile) throws IOException{
 2         //如果目标文件不存在,则创建
 3         File parentFile = toFile.getParentFile();
 4         if(!parentFile.exists()){
 5             parentFile.mkdirs();
 6         }
 7         if(!toFile.exists()){
 8             toFile.createNewFile();
 9         }
10         //复制文件
11         FileInputStream ins = new FileInputStream(fromFile);
12         FileOutputStream out = new FileOutputStream(toFile);
13         byte[] b = new byte[1024];
14         int n=0;
15         while((n=ins.read(b))!=-1){
16             out.write(b, 0, n);
17         }
18         
19         ins.close();
20         out.close();
21     }

 

Java复制文件

原文:https://www.cnblogs.com/tashaxing/p/8806582.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!