如何创建包含空间的目录路径

时间:2014-12-15 03:23:15

标签: android file-io runtimeexception

每当我的应用尝试在SD卡上创建目录时,它都会抛出运行时异常。 错误是

java.lang.RuntimeException: Could not create library directory /storage/sdcard0/Seafile/logan676@163.com (cloud.seafile.com)/personal folder

所以我的问题是,是否允许创建包含空格的目录。 我实现了如下代码。

if (path != null) {
        // Has record in database
        repoDir = new File(path);
        if (!repoDir.exists()) {
            if (!repoDir.mkdirs()) {
                throw new RuntimeException("Could not create library directory " + path);
            }
        }
        return path;
    }

我必须创建这种类型的目录,因为我在用户清除缓存时删除了它们。

/**
 * Deletes cache directory under a specific account<br>
 * remember to clear cache from database after called this method
 *
 * @param dirPath
 * @throws IOException
 */
public static void clearCache(String dirPath) throws IOException {
    // clear all cached files inside of the directory, the directory itself included
    File cacheDir = new File(dirPath);
    FileUtils.deleteDirectory(cacheDir);

}

此clearCache方法将删除根目录及其子目录。 那么它与上面的运行时异常有什么关系。

0 个答案:

没有答案