Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » 技术文章库  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 如何用java拷贝本地文件夹
wuchensir



发贴: 0
积分: 0
于 2003-10-27 16:15 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
声明:很多东西都是偶搜集整理实践过得,具体从那的来得也不清楚了,所以不著名出处

利用java本地拷贝文件及文件夹




如何实现文件夹对文件夹的拷贝呢?如果文件夹里还有文件夹怎么办呢?

接下来我就将我的方法演示给一些初学者,希望能够帮助你们!

/*
* CopyRight by http://www.designac.org/
*/
package copyfile;
import java.io.*;
/**
* @author Administrator
*
* Class Function:
*/
public class copyDirectory {
public static void main(String args[]) throws IOException {
String url1="C:/Downloads/kele";
String url2="d:/java/copyfile/copy";
(new File(url2)).mkdirs();
File[] file=(new File(url1)).listFiles();
for(int i=0;i<file.length;i++){
if(file[i].isFile()){
FileInputStream input=new FileInputStream(file[i]);
FileOutputStream output=new FileOutputStream(url2+"/"+file[i].getName());
byte[] b=new byte[1024*5];
int len;
while((len=input.read(b))!=-1){
output.write(b,0,len);
}
output.flush();
output.close();
input.close();
}
if(file[i].isDirectory()){
copyDirectiory(url2+"/"+file[i].getName(),url1+"/"+file[i].getName());
}
}
}
public static void copyDirectiory(String file1,String file2) throws IOException{
(new File(file1)).mkdirs();
File[] file=(new File(file2)).listFiles();
for(int i=0;i<file.length;i++){
if(file[i].isFile()){
FileInputStream input=new FileInputStream(file[i]);
FileOutputStream output=new FileOutputStream(file1+"/"+file[i].getName());
byte[] b=new byte[1024*5];
int len;
while((len=input.read(b))!=-1){
output.write(b,0,len);
}
output.flush();
output.close();
input.close();
}
if(file[i].isDirectory()){
copyDirectiory(file1+"/"+file[i].getName(),file2+"/"+file[i].getName());
}

}

}
}


floater edited on 2003-10-27 23:05


话题树型展开
人气 标题 作者 字数 发贴时间
17781 如何用java拷贝本地文件夹 wuchensir 1724 2003-10-27 16:15
15852 Re:如何用java拷贝本地文件夹 reddream 20 2003-11-27 14:33
15785 Re:如何用java拷贝本地文件夹 javaD 6 2003-12-02 17:21
15987 Re:如何用java拷贝本地文件夹 SQL20000 1155 2003-12-06 09:03
15896 Re:如何用java拷贝本地文件夹3 SQL20000 49 2003-12-06 09:05
15874 如何应用呀.. SQL20000 60 2003-12-06 09:09
15846 Re:如何用java拷贝本地文件夹 hotyaya 12 2004-02-15 07:58
15618 Re:如何用java拷贝本地文件夹 Lomone 32 2004-03-09 21:27
19483 Re:如何用java拷贝本地文件夹 PrimeJava 20 2004-03-16 17:05

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923