将文件保存到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上使用相同的代码没有问题。
答案 0 :(得分:3)
要访问保存的文件,您首先需要了解Application.persistentDataPath
指向的位置。 This帖子显示了它在大多数平台上的指向。
对于Andoid,它位于:
/Data/Data/com.<companyname>.<productname>/files
有SD卡可用时,位于:
/storage/sdcard0/Android/data/com.<companyname>.<productname>/files
这也取决于设备型号。在某些设备上,即使可用,它也不会保存在SD卡上。
使用Debug.Log
或Text
组件记录Application.persistentDataPath + "/results" + settings.IdentificationNumber + ".csv"
路径。这将向您显示在何处查找保存的文件。如果它不是保存在SD卡上,而是保存在/Data/Data/com.<companyname>.<productname>/files
上,请参见this帖子以获取如何获取/Data/Data
文件夹中的文件。