递归打印File文件夹目录信息–代码:
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 28 29 30 31 32 33 34 35 36 37
| package com.bhy.test_file;
import java.io.File;
public class TestListFile {
public static void main(String[] args) {
File f = new File("F:/java文件"); System.out.println(">"+f.getName()); getFileName(f,1); }
public static void getFileName(File f,int n) { int m = n; File[] file = f.listFiles(); for (File file2 : file) { for (int i = 0; i <= n; i++) { System.out.print(">"); } System.out.println(file2.getName()); if(file2.isDirectory()) { getFileName(file2,m+1); } } } }
|