package cuiyuee; import java.io.File; import java.util.ArrayList; import java.util.List; public class GetAllDirectory { public static void showDirectory(File file){ File[] files = file.listFiles(); for(File a:files){ System.out.println(a.getAbsolutePath()); if(a.isDirectory()){ showDirectory(a); } } } public static void main(String[] args) { // TODO Auto-generated method stub File file = new File("F:\java"); showDirectory(file); } }
执行结果如下
F:javachildDirectory
F:javachildDirectorycuiyuee1.txt
F:javacuiyuee.txt
F:javasongbo.txt