1
String fldr= "Main";

我需要查找目录中的任何位置是否有一个名为 fldr 的文件夹。

这将返回外部存储目录

String SDpath = Environment.getExternalStorageDirectory().toString();

如果有一个类似于 fldr 的文件夹,我需要获取它的目录并检查它是否可写.. 怎么做?

4

1 回答 1

3

这样做,

File dir = new File(Environment.getExternalStorageDirectory() + "/Main");
if(dir.exists() && dir.isDirectory()) {
    // do something here
}

/**
   * @return True if the external storage is available.
   * False otherwise.
   */
  public static boolean checkAvailable() {

    // Retrieving the external storage state
    String state = Environment.getExternalStorageState();

    // Check if available
    if (Environment.MEDIA_MOUNTED.equals(state)
        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      return true;
    }

    return false;
  }

  /**
   * @return True if the external storage is writable.
   * False otherwise.
   */
  public static boolean checkWritable() {

    // Retrieving the external storage state
    String state = Environment.getExternalStorageState();

    // Check if writable
    if (Environment.MEDIA_MOUNTED.equals(state)) {
      return true;
    }

    return false;

  }
于 2015-04-29T10:46:20.853 回答