首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Directory.createDirectory在iOS中创建文件而不是目录

Directory.createDirectory在iOS中创建文件而不是目录
EN

Stack Overflow用户
提问于 2016-10-06 13:01:13
回答 1查看 1.9K关注 0票数 1

为了统一游戏,我必须在iOS设备上保存一些本地数据。团结提供

代码语言:javascript
复制
    Application.persistentDataPath

以获取公共目录以保存数据。并在控制台上打印它,表明为iOS返回的路径是正确的,即iOS

因此,一个函数返回路径和其他检查目录是否存在,如果没有,它应该创建一个目录,但它创建的文件没有任何扩展名。这是我的密码

代码语言:javascript
复制
    void savePose(Pose pose){

        if (!Directory.Exists(PoseManager.poseDirectoryPath())){
            Directory.CreateDirectory(PoseManager.poseDirectoryPath());
            //Above line creates a file  
            //by the name of "SavedPoses" without any extension
        }
        // rest of the code goes here
    }

    static string poseDirectoryPath() {
        return Path.Combine(Application.persistentDataPath,"SavedPoses");
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-06 13:30:09

可能的偷懒行为:

1.Path.Combine(Application.persistentDataPath,"SavedPoses");savedPoses之前添加反斜杠,而其他则是正斜杠。也许这会在iOS上引起问题。尝试在没有Path.Combine函数的情况下连接原始字符串。

代码语言:javascript
复制
static string poseDirectoryPath() {
    return Application.persistentDataPath + "/" + "SavedPoses";
}

2.If Directory类不能正常工作,请使用DirectoryInfo类。

代码语言:javascript
复制
private void savePose(Pose pose)
{
    DirectoryInfo posePath = new DirectoryInfo(PoseManager.poseDirectoryPath());

    if (!posePath.Exists)
    {
        posePath.Create();
        Debug.Log("Directory created!");
    }
}

static string poseDirectoryPath()
{
    return Path.Combine(Application.persistentDataPath, "SavedPoses");
}

编辑

可能是iOS上的权限问题。

您可以在StreamingAssets目录中创建文件夹。您有读写此目录的权限。

访问它的一般方法是使用Application.streamingAssetsPath/

在iOS上,也可以使用Application.dataPath + "/Raw"访问它。

在安卓系统上,它也可以用"jar:file://" + Application.dataPath + "!/assets/";访问,对于Windows和Mac也可以用Application.dataPath + "/StreamingAssets";访问。就用对你有用的那个吧。

对于你的问题,Application.dataPath + "/Raw"+"/SavedPoses";应该这么做。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39896730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档