Unity3D 在安卓平台下访问StreamingAssets目录下文件,找不到的问题

http://www.ceeger.com/forum/read.php?tid=16174


public void Start(){        
    StartCoroutine(ontest());
   
}
IEnumerator ontest(){
    string persistentDataPath = Application.persistentDataPath +"/01.txt";
    Debug.Log(" persistentDataPath : "+persistentDataPath);
    if(!File.Exists(persistentDataPath)){
        string fileName  = Application.streamingAssetsPath + "/01.txt";
        Debug.Log("  fileName :"+fileName);
        if(File.Exists(fileName)){
            WWW www = new WWW(fileName);
            yield return www;
            if(!string.IsNullOrEmpty(www.error)){
                Debug.Log("==============load not error==========");
            }else{
                Debug.Log("=============load error==========");
                yield break;
            }
            if(www.isDone){
                Debug.Log("==============isDone==========");
                File.WriteAllBytes(persistentDataPath,www.bytes);
            }else{
                Debug.Log("==============not isDone==========");
            }
        }else{
            Debug.Log(fileName +" is not exists");
        }       
    }else{
        Debug.Log(persistentDataPath+" is exists");
    }
}

adb logcat -s Unity 打印的结果 
打印的结果

StreamingAssets



在ios 运行没有这种情况,android 不知道为毛出现这种情况! 
与本人出现类似情况的一个帖子 http://tieba.baidu.com/p/2431263861
分享:
zhmxy555
 
masterz
masterz  学徒  2014-03-22 14:38 1楼
安卓平台StreamingAssetszai 这样写:"jar:file:///" + Application.dataPath + "!/assets/";
waneta
waneta  学徒  2014-03-22 18:59 2楼
masterz:安卓平台StreamingAssetszai 这样写:"jar:file:///" + Application.dataPath + "!/assets/"; 回到原帖
"jar:file: //" + Application.dataPath + "!/assets/" 
是"jar:file: //" 不是"jar:file: ///" 吧! 
这个路径也没用。
asetbug
asetbug  学徒  2014-03-22 21:52 3楼
别用File.Exists(fileName)判断试试,我感觉由于android系统权限问题这个函数可能一直返回false
hawk
hawk  管理员  2014-03-22 23:53 4楼
用www获取
忧魂的眼泪
忧魂的眼泪  学徒  2014-03-23 16:04 5楼
dengqiang569
dengqiang569  学徒  2014-04-04 16:43 6楼
这路径好像是找不到,以前做截屏的时候保存路径也出现过这情况,你可以不必考虑路径是否存在,你直接读取路径下的资源就OK了
waneta
waneta  学徒  2014-04-08 16:37 7楼
dengqiang569这路径好像是找不到,以前做截屏的时候保存路径也出现过这情况,你可以不必考虑路径是否存在,你直接读取路径下的资源就OK了 回到原帖
看来只能这样了。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值