public class FileTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
FileTest ft = new FileTest();
File[] filelist = File.listRoots();
for(File f: filelist)
ft.listDir(f.toString());
}
public void listDir(String path){
File file = new File(path);
File[] filelist = file.listFiles();
if(filelist != null)
for(File f: filelist){
String pathn = path + "\\" + f.getName();
if(f.isDirectory()){
listDir(pathn);
}else;
System.out.println(pathn);
}
}
}
学了File类及常用方法后的小案例