import java.io.File; public class Test1 { public static void main(String[] args) { String path="d:/"; File file=new File(path); File[] tempList = file.listFiles(); System.out.println("该目录下对象个数:"+tempList.length); for (int i = 0; i < tempList.length; i++) { if (tempList[i].isFile()) { System.out.println("文 件:"+tempList[i]); } if (tempList[i].isDirectory()) { System.out.println("文件夹:"+tempList[i]); } }
for(int i=0;i<array.length;i++){ if(array[i].isFile()){ // only take file name System.out.println("^^^^^" + array[i].getName()); // take file path and name System.out.println("#####" + array[i]); // take file path and name System.out.println("*****" + array[i].getPath()); }else if(array[i].isDirectory()){ getFile(array[i].getPath()); } }
}
}