1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package File类;
import java.io.File;
public class DiGuiDemo2 {
public static void main(String[] args) { // TODO Auto-generated method stub File f=new File("D:\\steam"); getAllFile(f); } public static void getAllFile(File f) { File[] fileArray=f.listFiles(); if(fileArray!=null) { for(File file:fileArray) { //判断该file对象是否是目录 if(file.isDirectory()) { getAllFile(file); }else { System.out.println(file.getAbsolutePath()); } } } } }
|