Java访问文件夹中文件的递归遍历代码Demo
上代码:
import java.io.File; /*
* 需求:对指定目录进行所有内容的列出(包含子目录中的内容)
* 也可以理解为 深度遍历。
*/
public class FindAllFilesInFolder {
public static void main(String[] args) {
File dir = new File("E:\\zhanhui");
listAll(dir,0);
}
public static void listAll(File dir,int level) {
System.out.println(getSpace(level)+dir.getName());
//获取指定目录下当前的所有文件夹或者文件对象
level++;
File[] files = dir.listFiles();
for(int x=0; x<files.length; x++){ if(files[x].isDirectory()){
listAll(files[x],level);
}
else
System.out.println(getSpace(level)+files[x].getName());
}
}
private static String getSpace(int level) {
StringBuilder sb = new StringBuilder();
sb.append("|--");
for(int x=0; x<level; x++){
sb.insert(0,"| ");
}
return sb.toString();
}
}
Java访问文件夹中文件的递归遍历代码Demo的更多相关文章
- C# 将文件夹中文件复制到另一个文件夹
p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...
- python批量处理文件夹中文件的问题
用os模块读取文件夹中文件 原来的代码: import osfrom scipy.misc import imread filenames=os.listdir(r'./unprocess')for ...
- php获取指定文件夹中文件名称
/** * php获取指定文件夹中文件名称 * @author jackie <2018.10.10> */ public static function getFileName($fil ...
- Python按顺序读取文件夹中文件
参考资料: https://blog.csdn.net/qq_22227123/article/details/79903116 https://blog.csdn.net/merdy_xi/arti ...
- C#实现对指定文件夹中文件按修改时间排序
string path = "~/Document/Introduction/团队管理制度/"; DirectoryInfo dirinfo = new Di ...
- 【linux】复制文件夹中文件,排除部分文件
如下 cp `ls|grep -v -E '*json|out'|xargs` /home/data/ 用grep -v 表示排除, -E 表示正则 ls|grep -v -E '*json|out ...
- Python之获取文件夹中文件列表以及glob与fnmatch模块的使用
获取文件夹中的文件列表 print(os.listdir("../secondPackage")) # ['__init__.py', 'secondCookBook.py', ' ...
- 使用java读取文件夹中文件的行数
使用java统计某文件夹下所有文件的行数 经理突然交代一个任务:要求统计某个文件夹下所有文件的行数.在网上查了一个多小时没有解决.后来心里不爽就决定自己写一个java类用来统计文件的行数,于是花了两个 ...
- python文件夹中文件读取踩坑
Q: 进行数据集图片预处理时,初始命名如下图(Fig1左),发现读取文件时,读取的结构并非如所设想的那样顺序读取 Fig 1 A: pyhton读取文件的时候,按照文件名的ascii码中的顺序进行逐位 ...
随机推荐
- FortiGate外网IPSec链路及运维专线链路到个别网段不通
1.现状: 如图,用户网段有192.168.50.0/24.192.168.51.0/24和192.168.52.0/24.192.168.53.0/24.在防火墙上有静态路由到运维专线的10.160 ...
- 450. Delete Node in a BST 删除bst中的一个节点
[抄题]: Given a root node reference of a BST and a key, delete the node with the given key in the BST. ...
- Mobile Computing: the Next Decade论文 cloudlet薄云
1 Introduction “Information at your fingertips anywhere, anytime” has been the driving vision of mob ...
- swift 警告框 - 自定义按钮颜色,图片
1.封装 弹框http://www.hangge.com/blog/cache/detail_651.html import UIKit extension UIAlertController { / ...
- C# NPOI 日期格式
之前整理的NPOI导入导出Excel 在之前使用过程中没发现问题. 但是后来发现导入的文档如果有日期时间格式,导入时会有混乱 后来找了一下解决方案,最终将其中一段修改即可导入日期(导出未测试) 原因 ...
- Powershell 脚本判断制定路径下文件是否存在(来源于网络-转载)
$filelist=gc "file.txt" #获取要检查的文件列表 $csvs= new-object collections.arraylist #创建一个arraylist ...
- ES6 扩展运算符
ES6的扩展运算符则可以看作是rest参数的逆运算.可以将数组转化为参数列表. 如:console.log(1,...[2,3,4],5) //1 2 3 4 5 用于合并数组: [1,2, ...m ...
- 设计模式之模板模式 template
设计模式 模板模式如果有一个流程如下step1();step2();step3();step4();step5();其中step3() step5()是需要用户自己编写使用其他步骤是固定的那么可以写成 ...
- struts2遇到的一个问题。
2018-09-12 好几年没配过struts2了,今天想用最新版的配一下,一直不成功,后来才知道,一堆红色输出里面有这样一句 ERROR StatusLogger No log4j2 configu ...
- Linux - PS1
\[\e[1;32m\][\u ^_^ aliyun\[\e[1;35m\] \[\e[33m\]\w ]\n$\[\e[m\] set tabstop=4set expandtabset shift ...