Discuss / Java / 写了两个方法来完成

写了两个方法来完成

Topic source

coldcube

#1 Created at ... [Delete] [Delete and Lock User]
public class test {    public static void main(String[] args){        listFiles();    }    public static void listFiles(String... path) {        String deepth = "";        if(path.length == 0){            printFiles(System.getProperty("user.dir"),deepth);        }        else printFiles(path[0],deepth);    }    public static void printFiles (String path, String deepth){        File[] dir = new File(path).listFiles();        for (File f : dir) {            if (f.isDirectory()) {                System.out.println(deepth + f.getName() + "/");                printFiles(f.getPath(), deepth + " ");            }            else System.out.println(deepth + f.getName());        }    }}


  • 1

Reply