import java.io.File; import java.io.IOException; public class FindDirectories { public static void main(String[] args) { if (args.length == 0) args = new String[]{".."}; try { File pathName = new File(args[0]); //if(!pathName.exists()) return; String[] fileNames = pathName.list();//列出所有的文件和名称 for (int i = 0; i < fileNames.length; i++) { File f = new File(pathName.getPath(), fileNames[i]); if (f.isDirectory()) {//撞南墙 System.out.println(f.getCanonicalPath());//是文件夹就打印其目录 main(new String[]{f.getPath()});//列出指定目录和文件 } } } catch (IOException e) { e.printStackTrace(); } } }
列出指定目录的文件
最新推荐文章于 2022-12-13 11:39:28 发布