package com.yung.ppapi.util;
import java.io.File;
public class FileUtil {
/**
* 删除文件
*
* @param fileName
* @return
*/
public static boolean deleteFile(String fileName) {
return deleteFile(new File(fileName));
}
/**
* 删除文件,支持递归删除目录下的所有文件及子目录下所有文件
*
* @param dir 将要删除的文件目录
* @return boolean Returns "true" if all deletions were successful. If a
* deletion fails, the method stops attempting to delete and returns
* "false".
*/
public static boolean deleteFile(File file) {
if (file.isDirectory()) {
String[] children = file.list();
// 递归删除目录中的子目录下
for (int i = 0; i < children.length; i++) {
boolean success = deleteFile(new File(file, children[i]));
if (!success) {
return false;
}
}
}
// 目录此时为空,可以删除
return file.delete();
}
// public static void main(String[] args) {
// System.out.println(deleteDir("D:\\tmp\\zip"));
// }
}
楼主这么辛苦,请使用楼主的推荐码领取支付宝红包吧,记得一定要消费掉哦。双赢^_^。
1、打开支付宝首页搜索“8282987” 立即领红包。