代碼如下:
package org.sw;
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/"));
}
}