保存然后访问保存的文件



将文件保存到 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 上运行没有问题。

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

对于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上,请参阅这篇文章,了解如何获取/Data/Data文件夹中的文件。

最新更新