文件夹递归遍历
来源:互联网 发布:mac关闭页面快捷键 编辑:程序博客网 时间:2024/06/06 08:34
public class FileUtils {public static void listDirectory(File file) {//递归遍历文件夹及其子目录.if(!file.exists()){System.out.println("此路径不存在");}if(!file.isDirectory()){System.out.println("此路径不是文件夹.");}File[] files=file.listFiles();if(files!=null&&files.length>0){//说明此目录下存在文件或目录.for (File file2 : files) {if(file2.isDirectory()){listDirectory(file2);}else{System.out.println(file2.getAbsolutePath());}}}}}-----------------------------------------------------------------------------------------------------------------File file=new File("C:\\Users\\Administrator\\Desktop\\1.txt");if(!file.exists()){try {file.createNewFile();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}else{System.out.println(file.getName());file.delete();}//file.createNewFile():创建此抽象路径所表示的文件.(Atomically creates a new, empty file named by this abstract pathname if * and only if a file with this name does not yet exist.)//file.mkdir():创建此抽象路径所表示的一级目录.//file.mkdirs():创建此抽象路径所表示的多级目录.(* Creates the directory named by this abstract pathname, including any * necessary but nonexistent parent directories. Note that if this * operation fails it may have succeeded in creating some of the necessary * parent directories.)//file.delete():删除此抽象路径所表示的文件;或是此抽象路径所表示的目录(前提是这个目录必须为空,才能删除成功).//file.separator 或者用转义字符"\\"表示分隔符.//file.getName():返回该文件或目录的名字(包含文件扩展名).//file.getAbsolutelyPath():返回该文件或目录的绝对路径.//file.getParent():返回该文件或者目录的父目录的路径(* Returns the pathname string of this abstract pathname's parent, or *
null
if this pathname does not name a parent directory.).//file.listFiles():返回该目录下所有目录和文件的抽象路径对象所组成的数组.(* Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.)//file.list():返回该目录下所有目录和文件的名字(String Array.)(* Returns an array of strings naming the files and directories in the * directory denoted by this abstract pathname.)//file.exist():判断此抽象路径所表示文件或目录是否存在.(* Tests whether the file or directory denoted by this abstract pathname * exists.) 0 0
- 使用递归遍历文件夹
- 递归法遍历文件夹
- VBS递归遍历文件夹
- 非递归遍历文件夹
- 非递归遍历文件夹
- 递归遍历文件(文件夹)
- java 递归遍历文件夹
- 非递归遍历文件夹
- 文件夹递归遍历
- php递归遍历文件夹
- 非递归遍历文件夹
- 递归遍历文件夹脚本
- as3 递归 遍历文件夹
- 深度递归遍历文件夹
- JAVA递归遍历文件夹
- boost递归遍历文件夹
- C#递归遍历文件夹
- 递归:遍历指定文件夹
- 安卓自定义View进阶-事件分发机制原理
- 乘法逆元
- linux 网络接收 瓶颈示意图
- 通过shell的二维数组 跳入指定服务器
- linux初学<习题八>用快捷方式执行最近一条含有"date"关键字的命令!
- 文件夹递归遍历
- ant脚本编写
- 安卓自定义View进阶-事件分发机制详解
- Spring Cloud实战(三)-Spring Cloud Netflix Ribbon
- deeplearning—book—整理——intro
- webpack(一)
- FastDFS之添加机器同步
- shell 二维数组
- pdb