ios中while()不能www方式读取文件

void FDJson()
{using(WWW _load = new WWW("file://"+FileFunc.GetStreamPathRW("FontPreferenceC.json")))  //
   {while(!_load.isDone){}  }}

安卓却可以这样读取

经过修改

IEnumerator FDJson()
{using(WWW _load = new WWW("file://"+FileFunc.GetStreamPathRW("FontPreferenceC.json")))  //
    {while(!_load.isDone){yield return null;} }
}    

可以在ios下正常读取了

但是这个要用到IEnumerator 枚举器,很不方便,所以读取文件最好用system.io接口读取

public static string ReadTextFromFile (string path){if (System.IO.File.Exists (path)){return System.IO.File.ReadAllText (path, System.Text.Encoding.UTF8);}else return null;}

但io在安卓中不适用,因为安卓的文件都是jar压缩格式,所以在安卓中要用www读取文件,

http://answers.unity3d.com/questions/210909/android-streamingassets-file-access.html

So I was never able to figure out if it is possible to use the System.IO.FileInfo class to check the existence of a file that is added to your Android .APK file through the StreamingAssets directory. At this point I really doubt it's possible at all. The reason for this is that the .APK file is an archive, as you may know you can open a .APK file using any archiving utility (WinRAR for example) to inspect it's contents as I touched on above. So the FileInfo class apparently does not support archives like this.

Fortunately the WWW class does support a URI in the style of a JAR URL. So instead I am just pointing my WWW object at the location where the file might be (using the correct JAR URL syntax) and seeing if I come back with an error.

This forums post was extremely insightful in showing how exactly to open a file from the StreamingAssets folder. I'm kind of surprised that this issue isn't better documented, but hopefully in the future this post will save someone a lot of time.

In review:

  1. Don't use System.IO.FileInfo to access files that are archived in your .APK
  2. WWW is your best friend.
  3. The correct URI to access StreamingAssets on Android devices is: "jar:file://" + Application.dataPath + "!/assets/" + fileName

转载于:https://www.cnblogs.com/pengyingh/archive/2013/04/18/3029727.html

ios中while()和 android中的不同之处相关推荐

  1. android中的单例模式,Android中的单例模式

    定义: 单例模式:确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 使用场景: 确保某一个类有且只有一个对象的场景,避免产生多个对象消耗过多的资源,或者某种类型的对象只应该有且只有一 ...

  2. android中px单位,android中像素单位dp、px、pt、sp的比较

    dp(dip): device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不依赖 ...

  3. android中内存泄露,Android中的内存泄露

    编辑推荐: 本文来自于csdn,本文主要从java的内存模型讲起,最终举出几个内存泄露的例子和解决方案. java运行时内存模型 具体信息:http://gityuan.com/2016/01/09/ ...

  4. Android中list常用方法,Android中的常用控件及其基本用法

    TextView的使用方法 布局文件中的配置: 在Activity类中的使用: TextView textView1 = (TextView)findViewById(R.id.textView1); ...

  5. android中的加密算法,Android中加密算法

    Android中的加密算法可以分为两类:对称加密 和 非对称加密 对称加密(DES.3DES.AES) 概念 对称加密算法中,发送方将明文和加密密匙经过特殊加密算法处理后,使其形成变成复杂的密文后发送 ...

  6. android 中color目录,android中colors.xml颜色设置资源文件的方法

    1. 打开res目录下的values文件夹,双击打开colors.xml文件进行编辑 上代码 #008577 #00574B #D81B60 #ff0000 #0000ff 2. 在res目录下的la ...

  7. android中图片圆角,Android中实现圆角图片的几种方法

    Android中实现圆角图片有多种姿势,不知你解锁了几种? 方法一:setXfermode法 此种方式就是再new一个相同尺寸的bitmap,然后使用paint.setXfermode(new Por ...

  8. Kotlin 中Butterknife 和Android 中使用butterknife

    因为不太熟悉kotlin 所以就想写一个混编的Android  的测试 既有kotlin 又有android 的原生 目的:想了解下Kotlin ,和使用下Kotin中传说中的语法糖,别以后遇到大神写 ...

  9. Android中list常用方法,Android中ListActivity用法实例分析

    本文实例分析了Android中ListActivity用法.分享给大家供大家参考,具体如下: 程序如下: import android.app.ListActivity; import android ...

  10. Android中获取天气,android中获取即刻天气

    android中获取即时天气 先看效果: 需求非常简单,在菜单中加入天气查询的按钮,点击后显示即时天气. 准备工作: 1.下载华为能力SDK:http://imax.vmall.com/nj-camp ...

最新文章

  1. 并查集(边带权,拓展域)
  2. 即时通讯音视频开发(六):如何开始音频编解码技术的学习
  3. IOS基础之计算器的编写
  4. 中国内容推荐引擎市场趋势报告、技术动态创新及市场预测
  5. 读取敏感词库内容,讲某段字符里面的敏感词替换成*
  6. 步进电机加速的c语言编程,步进电机加速-匀速-减速运行程序(C - 电子制作 - 电子发烧友网...
  7. 松柏先生: 做品牌自己挣钱不算什么, 能让1000名山区绣娘都挣钱才牛!
  8. 营收增速环比放缓 Okta高歌猛进的那股劲去哪了?
  9. 阿里巴巴字体库使用方法
  10. 用c语言编写人机结合的加法,综合集成研讨厅中人机结合的研讨流程研究.pdf
  11. 客厅中式装修风格 温馨舒适的生活格调
  12. pdf如何做到批量格式转换?
  13. 怎样给计算机桌面设密码,怎样给电脑设置锁屏密码
  14. S32K144之SDK版:CAN模块应用
  15. Hibernate 主键使用注解 @SequenceGenerator
  16. 人工智能数学基础---定积分6:无穷限函数的反常积分计算
  17. Hurst指数python实现
  18. Packet Tracer - 交换机和终端设备的基本配置
  19. SQL Server 2012 AlwaysOn高可用配置之六:启用AlwaysOn功能
  20. jquery返回顶部特效代码 网页滚动返回顶部特效

热门文章

  1. 3、mybatis主配置文件之settings
  2. matlab遗传算法无人机问题,基于改进遗传算法的无人机路径规划
  3. 我们又双叒搬家了!(附福利)
  4. 干货!不得不知的UI界面中“行为召唤按钮”设计秘诀
  5. Ubuntu 10.04下SSH配置
  6. Activiti实战. 1.5Activiti架构与组件
  7. SQL转换函数to_char/to_date/to_number
  8. F# 和Silverlight 4
  9. 分享一下cookies操作(增、删、改、查)小经验
  10. 质量意味着在没有人看的时候把它做对