|
|
@@ -1,56 +1,28 @@
|
|
|
package com.sheep.jiuyan.samllsheep.utils;
|
|
|
|
|
|
-import android.content.Context;
|
|
|
-import android.os.Environment;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
|
|
/**
|
|
|
- * Created by kemllor on 2017/12/26.
|
|
|
+ * Created by realicing on 2018/6/1.
|
|
|
*/
|
|
|
|
|
|
public class FileUtil {
|
|
|
|
|
|
|
|
|
- public static String getAppPath(Context context) {
|
|
|
-
|
|
|
- if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
|
|
-
|
|
|
-
|
|
|
- return Environment.getExternalStorageDirectory().toString();
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- return context.getFilesDir().toString();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
public static void deleteFile(File file) {
|
|
|
- if (file.exists()) { // 判断文件是否存在
|
|
|
+ if (file != null && file.exists()) { // 判断文件是否存在
|
|
|
if (file.isFile()) { // 判断是否是文件
|
|
|
file.delete(); // delete()方法 你应该知道 是删除的意思;
|
|
|
} else if (file.isDirectory()) { // 否则如果它是一个目录
|
|
|
- File files[] = file.listFiles(); // 声明目录下所有的文件 files[];
|
|
|
- for (int i = 0; i < files.length; i++) { // 遍历目录下所有的文件
|
|
|
- deleteFile(files[i]); // 把每个文件 用这个方法进行迭代
|
|
|
+ File[] files = file.listFiles(); // 声明目录下所有的文件 files[];
|
|
|
+ if(files != null) {
|
|
|
+ for (int i = 0; i < files.length; i++) { // 遍历目录下所有的文件
|
|
|
+ deleteFile(files[i]); // 把每个文件 用这个方法进行迭代
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
file.delete();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public static String transForDate(Integer ms) {
|
|
|
- if (ms == null) {
|
|
|
- ms = 0;
|
|
|
- }
|
|
|
- long msl = (long) ms * 1000;
|
|
|
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- String str = "";
|
|
|
- if (ms != null) {
|
|
|
- str = format.format(msl);
|
|
|
- }
|
|
|
- return str;
|
|
|
- }
|
|
|
}
|