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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.tiptimes.util;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class FileUtil {
public FileUtil() {
}
public static String checkImgContentType(String string) {
String result = "";
String[] imgContentTypes = new String[]{"image/gif", "image/png", "image/jpeg", "image/jpg"};
String[] var3 = imgContentTypes;
int var4 = imgContentTypes.length;
for(int var5 = 0; var5 < var4; ++var5) {
String type = var3[var5];
if (type.equals(string)) {
result = "." + type.substring(type.lastIndexOf("/") + 1);
}
}
return result;
}
public static String checkVideoContentType(String string) {
String result = "";
String[] imgContentTypes = new String[]{"video/mp4"};
String[] var3 = imgContentTypes;
int var4 = imgContentTypes.length;
for(int var5 = 0; var5 < var4; ++var5) {
String type = var3[var5];
if (type.equals(string)) {
result = "." + type.substring(type.lastIndexOf("/") + 1);
}
}
return result;
}
public static boolean mkdirFolders(String strFilePath) {
boolean bFlag = false;
try {
File file = new File(strFilePath);
if (!file.exists()) {
bFlag = file.mkdirs();
} else {
bFlag = true;
}
if (bFlag) {
return true;
} else {
System.out.println("创建目录" + strFilePath + "失败!");
return false;
}
} catch (Exception var3) {
System.out.println("新建目录操作出错" + var3.getLocalizedMessage());
var3.printStackTrace();
return bFlag;
}
}
public static boolean deleteFile(String fileName) {
if (fileName != null && !"".equals(fileName)) {
File file = new File(fileName);
if (file.exists() && file.isFile()) {
if (file.delete()) {
System.out.println("删除单个文件" + fileName + "成功!");
return true;
} else {
System.out.println("删除单个文件" + fileName + "失败!");
return false;
}
} else {
return false;
}
} else {
return false;
}
}
public static boolean deleteDirectory(String dir) {
if (dir != null && !"".equals(dir)) {
if (!dir.endsWith(File.separator)) {
dir = dir + File.separator;
}
File dirFile = new File(dir);
if (dirFile.exists() && dirFile.isDirectory()) {
boolean flag = true;
File[] files = dirFile.listFiles();
for(int i = 0; i < files.length; ++i) {
if (files[i].isFile()) {
flag = deleteFile(files[i].getAbsolutePath());
if (!flag) {
break;
}
} else if (files[i].isDirectory()) {
flag = deleteDirectory(files[i].getAbsolutePath());
if (!flag) {
break;
}
}
}
if (!flag) {
System.out.println("删除目录失败!");
return false;
} else if (dirFile.delete()) {
System.out.println("删除目录" + dir + "成功!");
return true;
} else {
return false;
}
} else {
System.out.println("删除目录失败:" + dir + "不存在!");
return false;
}
} else {
return false;
}
}
public static File saveFileByInputStream(InputStream stream, String path, String filename) throws IOException {
File savaFile = new File(path + File.separator + filename);
FileOutputStream fps = new FileOutputStream(savaFile);
byte[] buffer = new byte[1048576];
int bytesum = 0;
boolean var7 = false;
int byteread;
while((byteread = stream.read(buffer)) != -1) {
bytesum += byteread;
fps.write(buffer, 0, byteread);
fps.flush();
}
fps.close();
stream.close();
return savaFile;
}
public static File copyFileByPath(String originPath, String targetPath, String targetPathForRepeat) throws IOException {
File targetFile = new File(targetPath);
try {
BufferedInputStream input = null;
if (originPath.startsWith("http")) {
input = new BufferedInputStream(new URL(originPath).openStream());
} else {
input = new BufferedInputStream(new FileInputStream(originPath));
}
FileOutputStream fps;
if (!targetFile.exists()) {
fps = new FileOutputStream(targetFile);
} else {
fps = new FileOutputStream(targetPathForRepeat);
}
byte[] buffer = new byte[1048576];
int bytesum = 0;
boolean var8 = false;
int byteread;
while((byteread = input.read(buffer)) != -1) {
bytesum += byteread;
fps.write(buffer, 0, byteread);
fps.flush();
}
fps.close();
input.close();
} catch (Exception var9) {
}
return targetFile;
}
}