zoukankan      html  css  js  c++  java
  • ios中while()和 android中的不同之处

    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
  • 相关阅读:
    Flink 多流转换算子
    Flink 基本算子map、keyBy、sum、reduce
    Scala 调用方法时加不加小括号
    Hive rank函数开窗
    Hive 窗口函数
    Scala 集合Map的基本操作
    LOJ#2402. 「THUPC 2017」天天爱射击 / Shooting 整体二分+树状数组
    LOJ#106. 二逼平衡树 树套树
    LOJ#2340. 「WC2018」州区划分
    LOJ#2304. 「NOI2017」泳池(70pts) dp
  • 原文地址:https://www.cnblogs.com/pengyingh/p/3029727.html
Copyright © 2011-2022 走看看