1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package com.example.myapplication.utils;
- import android.os.Environment;
- import java.io.File;
- import java.io.IOException;
- public class FileUtils {
- public static boolean checkSdCard() {
- if (Environment.getExternalStorageState().equals(
- Environment.MEDIA_MOUNTED)) {
- return true;
- } else {
- return false;
- }
- }
- public static void deleteFile(String path) {
- File file = new File(path);
- if (!file.isDirectory() && file.exists()) {
- file.delete();
- }
- }
- public static File updateDir = null;
- public static File updateFile = null;
- /***********
- * 保存升级APK的目录
- ***********/
- public static final String SD_SAVE_DIR = "butler";
- public static boolean isCreateFileSucess;
- public static void createDownFile() {
- if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
- isCreateFileSucess = true;
- updateDir = new File(Environment.getExternalStorageDirectory() + File.separator + SD_SAVE_DIR + File.separator);
- updateFile = new File(updateDir + "/" + SD_SAVE_DIR + ".apk");
- if (!updateDir.exists()) {
- updateDir.mkdirs();
- }
- if (!updateFile.exists()) {
- try {
- updateFile.createNewFile();
- } catch (IOException e) {
- isCreateFileSucess = false;
- e.printStackTrace();
- }
- }
- } else {
- isCreateFileSucess = false;
- }
- }
- public static void deleteDownFile() {
- if (updateFile != null && updateDir.exists()) {
- updateDir.delete();
- }
- }
- }
|