|
@@ -757,27 +757,32 @@ public class FileUtil {
|
|
|
* 删除文件或递归删除目录
|
|
|
* 递归删除目录下的所有文件及子目录下所有文件
|
|
|
*/
|
|
|
- public static boolean rm(File path) {
|
|
|
- if (path.isDirectory()) {
|
|
|
- String[] children = path.list();
|
|
|
- if (children != null) {
|
|
|
- for (String child : children) {
|
|
|
- boolean success = rm(new File(path, child));
|
|
|
- if (!success) {
|
|
|
- return false;
|
|
|
+ public static boolean rm(File file) {
|
|
|
+ if (!file.exists()) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ if (file.isDirectory()) {
|
|
|
+ String[] children = file.list();
|
|
|
+ if (children != null) {
|
|
|
+ for (String child : children) {
|
|
|
+ if (!rm(new File(file, child))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return file.delete();
|
|
|
}
|
|
|
}
|
|
|
- return path.delete();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除文件或递归删除目录
|
|
|
* 递归删除目录下的所有文件及子目录下所有文件
|
|
|
*/
|
|
|
- public static boolean rm(String path) throws Exception {
|
|
|
- return rm(getFile(path));
|
|
|
+ public static boolean rm(String path) {
|
|
|
+ return rm(new File(path));
|
|
|
}
|
|
|
|
|
|
|