特殊文件夹

简介

综合分析下不同平台、不同API的读写权限,以及对应的System.IOwww两种操作方式区别


读写方式
  • System.IO:部分平台部分API不可用
  • www:都可用,但要注意不同平台不同路径是否需要添加访问名称;正常可能是需要添加的,但Android平台的streamingAssetsPath的路径本身就是拥有前缀的,不需要额外加
    public void LoadByWWW(string path)
    {
        StartCoroutine(doLoadByWWW(path));
    }

    IEnumerator doLoadByWWW(string url)
    {
        WWW w = new WWW(url);
        yield return w;
        if (w.isDone){}
        else{}
    }

API
  • dataPath:
平台 可读 可写 路径 读写操作 备注
pc true true <项目地址>/Assets IO可以,www加前缀"file://" 该路径可以访问项目文件夹下的所有资源
android false false /data/app/xxx.xxx.xxx.apk IO和www都没用
ios true false Application/xxx-xx/xxx.app/Data IO没问题,www加前缀"file://"
  • streamingAssetsPath:
    这个文件夹中的资源在打包时会原封不动的打包进去,不会压缩,一般放置一些资源数据
平台 可读 可写 路径 读写操作 备注
pc true true <项目地址>/Assets/StreamingAssets IO可以,www加前缀"file://"
android true false jar:file:///data/app/xxx.xxx.xxx.apk/!/assets 不能IO,www不用加前缀直接用,路径自带前缀 路径相当于jar:file:// + dataPath + !/assets
ios true true Application/xxxxx-xxxx/xxx.app/Data/Raw IO可以,www加前缀"file://"
  • persistentDataPath:
    这个路径只能在程序运行时才能读写操作,不能提前将数据放入这个路径
平台 可读 可写 路径 读写操作 备注
pc true true C:/Users/xxx/AppData/LocalLow/DefaultCompany IO可以,www加前缀"file://"
android true true /data/data/xxx.xxx.xxx/files IO可以,www加前缀"jar:file://" 位置根据Write Access设置,可以是程序沙盒或者sdcard;如果保存在沙盒,就必须root才能用电脑取出文件,因此建议写入sdcard里
ios true true Application/x-xxxx-xxx/Documents IO可以,www加前缀"file://" 位置在应用程序的沙盒,可以被iCloud自动备份

你可能感兴趣的:(特殊文件夹)