java删除文件夹下所有文件示例分享
程序员文章站
2024-02-25 20:04:03
复制代码 代码如下:package org.sw;
import java.io.file;
public class deletefolder { &nbs...
复制代码 代码如下:
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/"));
}
}