File path=new File("D:\\aa\\bb";
File[] fileList=path.listFiles();
File[] fileList=path.listFiles();
解决方案 »
- ibtais+spring 操作sql2000 image字段类型 求助!
- Struts2+Spring+Hibernate下的一个莫名其妙的问题,求解
- 在hibernate字段映射中,我想自定义生成字段主键的生成方式,该如何做呢?
- 如何实现这种JSP验证码(特别是文字倾斜角度如何设置?)
- DB 数据库连接代码问题
- 请问我在JDK1。4的环境下如何引用javax.microedition.midlet.*
- 在Navicat for MYSQl运行sql文件错误
- 怎么用java写一个winnt下的service?
- 找一份web开发的工作(jsp)
- hibernate 查询 视图 与生成的 model不匹配.
- 新增记录后,如何取得自动编号字段的值?
- 请问一个问题
File[] fileList=path.listFiles();
import java.util.HashMap;
import java.util.Iterator;
public class FileList {
private String path;
private HashMap localList = new HashMap();
private long size = 0L;
public FileList(String path) {
this.path = path;
File dir = new File(path);
getDirectory(dir);
}
public void getDirectory(File file) {
File[] fileList = file.listFiles();
if (fileList == null) {
localList.put(file.getAbsolutePath(), file);
size += file.length();
return;
}
for (int i = 0; i < fileList.length; i++) {
localList.put(fileList[i].getAbsolutePath(), fileList[i]);
size += fileList[i].length();
if (fileList[i].isDirectory()) {
getDirectory(fileList[i]); //递归
}
}
}
public HashMap getLocalList() {
return localList;
}
public long getSize() {
return size;
}
public static void main (String args[]) { FileList fl = new FileList("E:\\work\\Test");
System.out.println("size " + fl.getSize());
HashMap hm = fl.getLocalList();
System.out.println("file count " + hm.size() );
Iterator a = hm.keySet().iterator();
while (a.hasNext()) {
System.out.println((String)a.next());
}
}
}
public class FileList
^
1 error