Topic: 一道不难的java题(拷贝一个文件夹及其子文件夹) |
Print this page |
1.一道不难的java题(拷贝一个文件夹及其子文件夹) | Copy to clipboard |
Posted by: zerog Posted on: 2006-08-15 16:11 “编写程序,使其能够拷贝一个文件夹及其子文件夹” 请问高手们,这个正确的编写步骤是怎样的? |
2.Re:一道不难的java题 [Re: zerog] | Copy to clipboard |
Posted by: zcjl Posted on: 2006-08-15 16:35 1.判断URL是否文件夹,是则跳到步骤3 2.构造目标文件的URL,并通过IO进行文件复制 3.遍历文件夹下的所有文件(夹),以每个文件(夹)的URL作为条件进入到步骤1(递归) |
3.Re:一道不难的java题(拷贝一个文件夹及其子文件夹) [Re: zerog] | Copy to clipboard |
Posted by: zerog Posted on: 2006-08-15 16:47 我是个初学者,您说的很难理解,能否把代码写下来呢!? |
4.Re:一道不难的java题(拷贝一个文件夹及其子文件夹) [Re: zerog] | Copy to clipboard |
Posted by: why Posted on: 2006-08-15 16:49 http://javaalmanac.com/egs/java.io/CopyDir.html?l=new |
5.Re:一道不难的java题(拷贝一个文件夹及其子文件夹) [Re: zerog] | Copy to clipboard |
Posted by: zerog Posted on: 2006-08-15 19:01 还是不太明白怎么把大侠说的三步编程代码,我看了why给我的例子,但是只是其中一部分,我又把几步写在一起,但是不知道具体怎么写,下面是我自己写的,很乱,不知道怎么写?希望哪位大侠给纠正下! public class test { public static void show(){ File file = new File("f:/test"); File dir = new File("g:/TEST"); if(file.isDirectory()) { if(!dir.isDirectory()) { String[] str = dir.list(); for (int i=0; i<str.length; i++) { show(new File(dir, str[i])); } dir.mkdir(); } String[] str = file.list(); for(int i=0; i<str.length; i++){ show(new File(file, str[i]),new File(dir,str[i])); } }else copyFile (file,dir); } |
6.Re:一道不难的java题(拷贝一个文件夹及其子文件夹) [Re: zerog] | Copy to clipboard |
Posted by: why Posted on: 2006-08-16 03:50 閣下寫過HelloWorld.java嗎? 不明白閣下為何要把copyDirectory改亂了
or
or use org.apache.commons.io.FileUtils http://jakarta.apache.org/commons/io/api-release/org/apache/commons/io/FileUtils.html |
7.Re:一道不难的java题(拷贝一个文件夹及其子文件夹) [Re: why] | Copy to clipboard |
Posted by: zcjl Posted on: 2006-08-16 09:21 真是佩服WHY的耐心和细致,不知道楼主对此还有什么问题吗? |
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 |