FileUtils.java
2.45 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.polysoft.nafmii.utils;
import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.text.TextUtils;
import java.io.File;
public class FileUtils {
public static File getIndex() {
return WebVersionUtils.getIndex();
}
public static File getDistDir() {
return WebVersionUtils.getDistDir();
}
public static File getDownloadDir() {
File download = new File(getRootDir(), "download");
if (!download.exists()) {
download.mkdirs();
}
return download;
}
public static File getSysDownLoadDir() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// return CtxUtils.getApplication().getExternalFilesDir();
}
public static File getRootDir() {
return CtxUtils.getApplication().getFilesDir();
}
// 获取热跟新目录
public static File getHotDir() {
File hot = new File(getRootDir(), "Hot");
if (!hot.exists()) {
hot.mkdirs();
}
return hot;
}
public static File getRootCacheDir() {
return CtxUtils.getApplication().getCacheDir();
}
public static void deletes(File file) {
if (file.isDirectory()) {
for (File f : file.listFiles()) {
deletes(f);
}
}
file.delete();
}
public static String getFileName(String name) {
int nameMaxLength = 60;
if (!TextUtils.isEmpty(name)) {
if (name.length() > nameMaxLength) {
String newname = name.substring(0, nameMaxLength);
String[] split = name.split("\\.");
if (split.length > 1) {
return newname + "." + split[split.length - 1];
}
return newname;
}
return name;
}
return "";
}
public static String getUrlFileName(String url) {
if (!TextUtils.isEmpty(url)) {
String[] split = url.split("/");
if (split.length > 1) {
String name = split[split.length - 1];
return getFileName(name);
}
}
return "";
}
public static void openFile(Context context, File file) {
if (!file.exists()) {
return;
}
Uri uri = FileProviderUtils.getUriForFile(context, file);
IntentUtils.startOpenFile(context, uri);
}
}