参考一下下面的代码:
try {
File f = new File("");
String sPath = f.getAbsolutePath();
File dir = new File(path);
try {
File[] files = dir.listFiles();
}
catch(SecurityException e1) { }
}
catch (NullPointerException e2) {
return;
}files数组中存放的就是当前目录下所有的文件。
try {
File f = new File("");
String sPath = f.getAbsolutePath();
File dir = new File(path);
try {
File[] files = dir.listFiles();
}
catch(SecurityException e1) { }
}
catch (NullPointerException e2) {
return;
}files数组中存放的就是当前目录下所有的文件。
void listPath(file path){
File files[];
Vector v;
files = path.listFiles();
for(int i=0,n=files.length;i<n;i++){
v.addElement(files[i]);
if(files[i].isDirectory()){
listPaht(files[i]);
}
}
}