本文章分享一篇关于java中文件夹遍历与统计文件夹中文件总行数据,有需要学习的朋友可以参考一下本文章哦。
先来看文件夹遍历
代码如下 | 复制代码 | ||||
//By LYLtim import java.io.File; public class TestFile { public static void main(String[] args) { File f = new File("D:/Temp/LYLtim_OI"); System.out.println(f.getName()); list(f, 0); } static void list(File f, int lv) { File[] childs = f.listFiles(); for (int i = 0; i < childs.length; i ) { for (int j = 0; j < lv; j ) System.out.print(" ┃"); if (i == childs.length - 1) System.out.println(" ┗" childs[i].getName()); else System.out.println(" ┣" childs[i].getName()); if (childs[i].isDirectory()) list(childs[i], lv 1); } } } 再看Java统计文件夹中文件总行数
|