package hello.IO;
import java.io.File;
import java.io.IOException;
public class IO {
public static void main(String[] args) {
}
//遍历目录
//文件测试
//重命名
static void test6() {
}
//获得文件信息
static void test5() {
File f = new File("");
boolean b = f.delete();
String name = f.getName();
String ap = f.getAbsolutePath();
// f.renameTo(f);
b = f.canRead();
File[] files = f.listFiles();
assert files != null;
for (File f1: files) {
System.out.print(f1.getName());
}
}
//删除文件
static void test4() {
File f = new File("");
boolean b = f.delete();
String name = f.getName();
String ap = f.getAbsolutePath();
}
//创建目录
static void test3() {
File f = new File("c:\\a\\b\\c");
boolean b = f.mkdirs();
}
//创建文件
static void test2() throws IOException {
File f = new File("c:\\a.txt");
boolean b = f.createNewFile();
}
static void test1() {
String path = "C:\\java\\hello";
File f = new File(path);
}
}
java文件和目录
最新推荐文章于 2023-03-21 17:01:42 发布