ba0a4fd2638702b114fd9b0d0c4460bce60d1c2b.svn-base 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.example.myapplication.utils;
  2. import android.os.Environment;
  3. import java.io.File;
  4. import java.io.IOException;
  5. public class FileUtils {
  6. public static boolean checkSdCard() {
  7. if (Environment.getExternalStorageState().equals(
  8. Environment.MEDIA_MOUNTED)) {
  9. return true;
  10. } else {
  11. return false;
  12. }
  13. }
  14. public static void deleteFile(String path) {
  15. File file = new File(path);
  16. if (!file.isDirectory() && file.exists()) {
  17. file.delete();
  18. }
  19. }
  20. public static File updateDir = null;
  21. public static File updateFile = null;
  22. /***********
  23. * 保存升级APK的目录
  24. ***********/
  25. public static final String SD_SAVE_DIR = "butler";
  26. public static boolean isCreateFileSucess;
  27. public static void createDownFile() {
  28. if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
  29. isCreateFileSucess = true;
  30. updateDir = new File(Environment.getExternalStorageDirectory() + File.separator + SD_SAVE_DIR + File.separator);
  31. updateFile = new File(updateDir + "/" + SD_SAVE_DIR + ".apk");
  32. if (!updateDir.exists()) {
  33. updateDir.mkdirs();
  34. }
  35. if (!updateFile.exists()) {
  36. try {
  37. updateFile.createNewFile();
  38. } catch (IOException e) {
  39. isCreateFileSucess = false;
  40. e.printStackTrace();
  41. }
  42. }
  43. } else {
  44. isCreateFileSucess = false;
  45. }
  46. }
  47. public static void deleteDownFile() {
  48. if (updateFile != null && updateDir.exists()) {
  49. updateDir.delete();
  50. }
  51. }
  52. }