Files
javaSE-0113/javaSE-day08/src/com/inmind/file01/FileDemo06.java

39 lines
975 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.file01;
import java.io.File;
/*
public boolean delete() 删除由此File表示的文件或目录。
注意:
1.如果一个文件夹中还有子内容,这个文件夹不允许直接删除,先删除所有子内容,才能删除父文件夹
2.删除方法是物理删除,不能恢复
*/
public class FileDemo06 {
public static void main(String[] args) {
//删除文件
File file = new File("a.txt");
if (file.exists()) {
file.delete();
}
//删除文件夹
File file1 = new File("b.txt");
if (file1.exists()) {
file1.delete();
}
//删除带有子内容的文件夹
File file2 = new File("b/a");
if (file2.exists()) {
file2.delete();
}
File file3 = new File("b");
if (file3.exists()) {
file3.delete();
}
System.out.println("程序结束");
}
}