-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathFileUtil.java
More file actions
66 lines (60 loc) · 1.76 KB
/
FileUtil.java
File metadata and controls
66 lines (60 loc) · 1.76 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
66
package common.base.utils;
import androidx.annotation.WorkerThread;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* *****************(^_^)***********************<br>
* User: fee(QQ/WeiXin:1176610771)<br>
* Date: 2021/4/24<br>
* Time: 22:42<br>
* <P>DESC:
* 操作文件的工具类
* </p>
* ******************(^_^)***********************
*/
public class FileUtil {
public static boolean writeStrContentToFile(String content, String fileAbsPath,boolean toAppendFileEnd) {
boolean isWritenOk = false;
FileWriter fw = null;
try {
fw = new FileWriter(fileAbsPath, toAppendFileEnd);
fw.write(content);
isWritenOk = true;
} catch (Exception exception) {
exception.printStackTrace();
}finally {
if (fw != null) {
try {
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return isWritenOk;
}
@WorkerThread
public static boolean deleteFileOrDir(String filePath) {
if (CheckUtil.isEmpty(filePath)) {
return false;
}
try {
boolean isOptSuc = false;
File theFile = new File(filePath);
if (theFile.exists()) {
if (theFile.isFile()) {
isOptSuc = theFile.delete();
}else if(theFile.isDirectory()) {
//文件夹需要递归删除
StorageUtil.deleteFile(theFile);
}
}
return isOptSuc;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}