保存然后访问保存的文件

时间:2018-08-14 20:01:25

标签: c# unity3d save

将文件保存到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();

让我在PC上使用相同的代码没有问题。

1 个答案:

答案 0 :(得分:3)

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

对于Andoid,它位于:

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

有SD卡可用时,位于:

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

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


使用Debug.LogText组件记录Application.persistentDataPath + "/results" + settings.IdentificationNumber + ".csv"路径。这将向您显示在何处查找保存的文件。如果它不是保存在SD卡上,而是保存在/Data/Data/com.<companyname>.<productname>/files上,请参见this帖子以获取如何获取/Data/Data文件夹中的文件。