Java中File操作

File的构造方法,其更多的API可以查看JDK-API:https://blog.csdn.net/HeZhiYing_/article/details/96146661

这里演示两种构造方法,并调用createNewFile()来创建文件

import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        File file = new File("D:\\my\\new.txt");

        File file1 = new File("D:\\my","a.txt");
        try {
            boolean b = file.createNewFile();
            boolean b1 = file1.createNewFile();
            System.out.println(b);
            System.out.println(b1);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

创建目录

import java.io.File;

public class Main {
    public static void main(String[] args) {
        File file = new File("D:\\my\\test");
        boolean b = file.mkdir(); //创建出file的目录
        System.out.println(b);
    }
}

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页