如何遍历列出ftp下目录及子目录?

如题所述

import java.io.File;

public class ListFile {

private long[] count = new long[] { 0, 0 };

private File file;

private long[] listFile(String path) {
file = new File(path);
File[] f = file.listFiles();
for (int i = 0; i < f.length; i++) {
if (f[i].isDirectory()) {
count[0]++;
this.listFile(f[i].getPath());
} else {
count[1]++;
}
}
return count;
}

/**
* 得到指定路径下的文件和文件夹数量
*
* @param path
* 要查看的路径
* @return object[0]耗时(毫秒)<br>
* object[1]文件夹数量<br>
* object[2]文件数量
*/
public Object[] getFileCount(String path) {
long t = System.currentTimeMillis();
long[] count = this.listFile(path);
t = System.currentTimeMillis() - t;
Object[] o = new Object[] { Long.valueOf(t), Long.valueOf(count[0]),
Long.valueOf(count[1])};
return o;
}

public static void main(String[] args) {
ListFile l = new ListFile();
Object[] count = l.getFileCount("d:\\");
System.out.println(count[0]);
System.out.println(count[1]);
System.out.println(count[2]);
}
}

java写的一个获取目录下有多少文件和多少文件夹的代码,
可以参考下.:)
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-08-01
要求什么语言啊

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网