-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileUtils.java
More file actions
34 lines (30 loc) · 969 Bytes
/
Copy pathFileUtils.java
File metadata and controls
34 lines (30 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package tony.nice.yuan;
import java.io.*;
public class FileUtils {
public static void main(String[] args){
String path = "D:\\a\\b\\c\\";
File dir = new File(path);
//create directory
boolean successFlag = emptyDictory(dir);
System.out.print(successFlag);
}
public static boolean emptyDictory(File file){
boolean flag = false;
//the arg is invalid or the path is not exist
if(null ==file || !file.exists()){
return true;
}
if(file.isDirectory()){
File[] fileArr = file.listFiles();
int length = fileArr.length;
for(int index = 0;index < length;index++){
emptyDictory(fileArr[index]);
}
// delete current directory
flag = file.delete();
}else{ //delete file
flag = file.delete();
}
return flag;
}
}