import java.io.File;

public class GetFoldFileNames {

/**
 *
 * @author zdz8207
 */
public static void main(String[] args) {
    String path= "/"; // 路径
    File f = new File(path);
    getFileName(f);
}


public static void getFileName(File f) {
    //String path= "/home/cnking"; // 路径
    //File f = new File(path);
    if (!f.exists()) {
        System.out.println(" not exists");
        return;
    }

    File fa[] = f.listFiles();
    for (int i = 0; i < fa.length; i++) {
        File fs = fa[i];
        if (fs.isDirectory()) {
            // File[] t =  fs.listFiles();
            getFileName(fs);


            System.out.println(fs.getName() + " [目录]");
        } else {
            System.out.println(fs.getName());
        }
    }
}

}

Logo

更多推荐