【问题标题】:unable to create directory with name .dirname on nexus 5无法在 nexus 5 上创建名为 .dirname 的目录
【发布时间】:2014-03-06 13:43:38
【问题描述】:

我无法在 android kitket(nexus 5) 中创建名为 .dirname 的目录。所以请建议我如何解决这个问题。当我调用 mkdirs() 方法时它返回 false 但是我已经在 android manifest 文件上设置了所有权限。

以下是我的代码:-

Map<String, File> externalLocations = ExternalStorage
                .getAllStorageLocations();
        File sdCard = externalLocations.get(ExternalStorage.SD_CARD);
        File externalSdCard = externalLocations
                .get(ExternalStorage.EXTERNAL_SD_CARD);
        Environment.getExternalStorageState();
       // long count = System.currentTimeMillis();
        if (sdCard == null) {
            path = null;
        } else { 
            path = sdCard.getAbsolutePath().toString() +"/.DriverMaticsV/" + "12345" + "/Picture/";
        }
        if (externalSdCard != null) {
            if (storageLocInt == 0) {
                path = sdCard.getAbsolutePath().toString() +"/.DriverMaticsV/" + "12345" + "/Picture/";
            } else {
                path = externalSdCard.getAbsolutePath().toString() + "/.DriverMaticsV/" + "12345" + "/Picture/";
            }
        }
        File file = new File(path);
        if (!file.exists()) {
            boolean result = file.mkdirs();
            Utilities.showDLog("CamperaUtil", ""+result);
        }

Android Manifest 权限:-

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application>.....</application>

【问题讨论】:

  • 无代码 = 它从未发生过 :)
  • 请检查我的代码。

标签: android


【解决方案1】:

我认为“dirname”是 linux 中的命令名,你不能在 linux 中使用命令名创建目录,我建议将 android 设备连接到 windows 机器并从 windows commad 提示符创建目录。

【讨论】:

  • 不,不是。第一件事是,如果您在目录后面加上“。”,则“目录名”只是示例名称。然后它在 mkdirs() 上产生问题,然后我的设备连接了窗口系统。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-06
  • 1970-01-01
  • 1970-01-01
  • 2016-08-24
  • 1970-01-01
  • 1970-01-01
  • 2021-09-02
相关资源
最近更新 更多