package com.itranswarp.learnjava; import java.io.*; public class Main { public static void main(String[] args) throws IOException { String fpath = "."; File f = new File(fpath); printPath(f, ""); // System.out.println(f.getName()); // System.out.println(f.getAbsolutePath()); // System.out.println(f.getCanonicalPath()); } public static void printPath(File file, String str) throws IOException { if(file.listFiles() != null) { for(File f1 : file.listFiles()) { if(f1.isDirectory()) { // 是文件夹 System.out.println(str +f1.getName() + "\\"); printPath(f1, str + " " ); }else { System.out.println(str + f1.getName()); } } } } }
Sign in to make a reply
用户7570525982