时间:2020-11-15 14:18:53 | 栏目:JAVA代码 | 点击:次
import java.io.File;
public class DeleteFolder {
/**
* 删除文件夹下的所有文件
* @param oldPath
*/
public void deleteFile(File oldPath) {
if (oldPath.isDirectory()) {
System.out.println(oldPath + "是文件夹--");
File[] files = oldPath.listFiles();
for (File file : files) {
deleteFile(file);
}
}else{
oldPath.delete();
}
}
public static void main(String[] args) {
DeleteFolder df = new DeleteFolder();
df.deleteFile(new File("E:/ddd/"));
}
}