【问题标题】:Saving and then accessing saved file保存然后访问保存的文件
【发布时间】:2018-08-14 20:01:24
【问题描述】:

将文件保存到 android 上的持久数据路径后如何访问文件? 我翻遍了我的手机文件,但找不到保存的文件。 当我运行调试时,它指向我手机上不存在的位置? 存储/模拟/0

对于我使用流编写器的代码

string[][] output = new string[rowData.Count][];

for (int i = 0; i < output.Length; i++)
{
    output[i] = rowData[i];
}

int length = output.GetLength(0);
string delimiter = ",";

StringBuilder sb = new StringBuilder();

for (int index = 0; index < length; index++)
    sb.AppendLine(string.Join(delimiter, output[index]));


string filePath = getPath();

StreamWriter outStream = System.IO.File.CreateText(Application.persistentDataPath + 
    "/results" + settings.IdentificationNumber + ".csv");
outStream.WriteLine(sb);
outStream.Close();

让相同的代码在电脑上运行没有问题。

【问题讨论】:

    标签: c# unity3d save


    【解决方案1】:

    要访问保存的文件,您首先需要了解Application.persistentDataPath 指向的位置。 This 帖子显示了它在大多数平台上指向的位置。

    对于 Andoid,位于:

    /Data/Data/com.<companyname>.<productname>/files
    

    当 SD 卡可用时,它位于:

    /storage/sdcard0/Android/data/com.<companyname>.<productname>/files
    

    这也取决于设备型号。在某些设备上,即使 SD 卡可用,它也不会保存在 SD 卡上。


    使用Debug.LogText 组件记录Application.persistentDataPath + "/results" + settings.IdentificationNumber + ".csv" 路径。这将告诉您在哪里查找保存的文件。如果不是保存在 SD 卡上而是保存在/Data/Data/com.&lt;companyname&gt;.&lt;productname&gt;/files 上,请参阅this 帖子了解如何获取/Data/Data 文件夹中的文件。

    【讨论】:

      猜你喜欢
      • 2018-06-11
      • 1970-01-01
      • 2018-06-03
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 1970-01-01
      • 1970-01-01
      • 2019-02-14
      相关资源
      最近更新 更多