java的File类删除功能


import java.io.File;

//删除文件
public class FileDemo4 {
    public static void main(String[] args) {
        //1.删除文件
        File file = new File("E:\\Workpace\\java.txt");
        System.out.println(file.delete());
        //2.删除文件夹
        File file1 = new File("E:\\Workpace\\java");
        System.out.println(file1.delete());
        //3.文件夹中有文件,则不能直接删除
        boolean file3 = new File("E:\\Workpace\\javaweb\\Html").delete();
        File file2 = new File("E:\\Workpace\\javaweb");
        System.out.println(file2.delete());
    }
}

posted @ 2021-04-30 23:19  code-G  阅读(420)  评论(0编辑  收藏  举报