package com;import java.util.*;
import java.io.*;public class Untitled1 {
public Untitled1() {
} public static void main(String[] args) {
String strPath = "c:/j2sdk_1.4.2_11/";
ArrayList al = new ArrayList();
List reValue = new Untitled1().getTree(strPath, al);
System.out.println("########################");
System.out.println("Start==" + reValue);
System.out.println("End==" + reValue.size());
System.out.println("########################");
} public List getTree(String strPath, ArrayList al) {
File file = new File(strPath);
File list[] = file.listFiles();
boolean isDir = false;
for (int i = 0; i < list.length; i++) {
isDir = list[i].isDirectory();
if (isDir) {
new Untitled1().getTree(list[i].toString(), al);
}
else {
al.add(list[i]);
}
}
return al;
}
}
import java.io.*;public class Untitled1 {
public Untitled1() {
} public static void main(String[] args) {
String strPath = "c:/j2sdk_1.4.2_11/";
ArrayList al = new ArrayList();
List reValue = new Untitled1().getTree(strPath, al);
System.out.println("########################");
System.out.println("Start==" + reValue);
System.out.println("End==" + reValue.size());
System.out.println("########################");
} public List getTree(String strPath, ArrayList al) {
File file = new File(strPath);
File list[] = file.listFiles();
boolean isDir = false;
for (int i = 0; i < list.length; i++) {
isDir = list[i].isDirectory();
if (isDir) {
new Untitled1().getTree(list[i].toString(), al);
}
else {
al.add(list[i]);
}
}
return al;
}
}
那得new出多少个对象呀
public static void list(File path) {
if (path.isFile()) {
System.out.println(path);
} else {
File[] files = path.listFiles();
for (int i = 0; i < files.length; i++) {
list(files[i]);
}
}
}
File path = new File("D:\\jdk1.5.0_06");
list(path);