-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFileUtils.java
More file actions
65 lines (54 loc) · 1.26 KB
/
FileUtils.java
File metadata and controls
65 lines (54 loc) · 1.26 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.realmo.utils;
import java.io.File;
/**
* @author Realmo
* @version 1.0.0
* @name FileUtils
* @email momo.weiye@gmail.com
* @time 2018/1/8 10:47
* @describe
*/
public class FileUtils {
/**
* @param path
* @return 文件大小
*/
public static long getFileSize(String path) {
long size = 0;
File file = new File(path);
if (file.exists()) {
size = file.length();
}
return size;
}
/**
* delete file
* @param path
*/
public static void deleteFile(String path) {
deleteFile(new File(path));
}
/**
* delete path
* @param file
*/
public static void deleteFile(File file) {
if(file.exists()){
if (file.isFile()) {
file.delete();
return;
}
if (file.isDirectory()) {
File[] childFiles = file.listFiles();
if (childFiles == null || childFiles.length == 0) {
file.delete();
return;
}
for (int i = 0; i < childFiles.length; i++) {
deleteFile(childFiles[i]);
}
file.delete();
}
}
}
}