【发布时间】:2018-05-28 00:37:17
【问题描述】:
这就是我在 android 中读取文本文件的方式。
#if UNITY_ANDROID
string full_path = string.Format("{0}/{1}",Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder);
// Android only use WWW to read file
WWW reader = new WWW(full_path);
while (!reader.isDone){}
json = reader.text;
// PK Debug 2017.12.11
Debug.Log(json);
#endif
这就是我从电脑读取文本文件的方式。
#if UNITY_STANDALONE
string full_path = string.Format("{0}/{1}", Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder);
StreamReader reader = new StreamReader(full_path);
json = reader.ReadToEnd().Trim();
reader.Close();
#endif
现在我的问题是我不知道如何在移动设备上编写文件,因为我在独立设备上这样做
#if UNITY_STANDALONE
StreamWriter writer = new StreamWriter(path, false);
writer.WriteLine(json);
writer.Close();
#endif
帮助任何人
更新问题
【问题讨论】:
-
无法真正验证,但您的独立代码应该可以在 android 上运行。你在手机上做的方式相当于从网络上读取文件,而你不能写入网络。
-
那么在 WWW 类上没有实际的方法吗? @Draco18s
-
StreamWriter writer = new StreamWriter(path, false); writer.WriteLine(json); writer.Close();当我尝试在移动设备上使用它时,我的 catch(Exception e) 说System.IO.DirectoryNotFoundException: Could not find a part of the path "/jar:file:/data/app/com.steet383.rh.google-1/base.apk!/assets/notice.json". -
我的错误。我远离开发环境,无法检查。 WWW不太可能让你写,但我不知道你的替代品是什么。
-
hmmm 我什么都没有 :( 。我已经尝试了几个小时,我已经看到很多他们正在使用持久数据,但问题是我需要从aws 服务器并将其取回。这就是我的问题。
标签: c# android json unity3d web