Java-I/O框架11:文件夹操作
package com.yundait.Demo05;
import java.io.File;
import java.util.Date;
public class DirectoryOpeDemo01 {
public static void main(String[] args) throws InterruptedException {
directoryOpe();
}
public static void directoryOpe() throws InterruptedException {
//1创建文件夹
File dir = new File("C:\\333\\666\\888");
System.out.println(dir.toString());
if (!dir.exists()){
// file.mkdir();//用于创建单个文件夹
System.out.println(dir.mkdirs());//用于创建多级目录
}
//2删除文件夹
//2.1直接删除
// System.out.println(dir.delete());
//2.2只用jvm退出删除
// dir.deleteOnExit();
// Thread.sleep(5000);
//3.获取文件信息
System.out.println("文件夹的绝对路径:" + dir.getAbsoluteFile());
System.out.println("文件夹的路径:" + dir.getPath());
System.out.println("文件夹的名称:" + dir.getName());
System.out.println("文件夹的父目录:" + dir.getParent());
System.out.println("文件夹的最后修改时间:" + new Date(dir.lastModified()));
//3 判断
System.out.println("是否是文件夹:" + dir.isDirectory());
System.out.println("是否是隐藏文件夹:" + dir.isHidden());
//4遍历
System.out.println("==================================");
File dir2 = new File("C:\\Users\\Administrator\\Pictures\\Saved Pictures");
String[] list = dir2.list();
assert list != null;//断言list不等于空
for (String s : list) {
System.out.println(s);
}
}
}
原文地址:https://blog.csdn.net/zhangjinajian759/article/details/143580357
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!