我的应用程序遇到了一个非常令人沮丧的问题,我正在使用 Vuforia,并且我正在尝试从运行时编辑流媒体 Assets 中的 xml 并将其保存,但是,我收到以下异常: UnauthorizedaccessException ... 访问路径被拒绝。
我尝试通过简单地使用将 XMLDocument 保存到路径来保存这两者,这是我得到 UnauthorizedaccessException 的地方,但也尝试过 Windows.Storage 命名空间,在这里我得到一个异常,说我的路径无效。
这里我得到了 UnauthorizedaccessException:
xmlDoc.Save(path);
这里我得到路径无效。
var folderPath = Path.Combine(Application.streamingAssetsPath, "Vuforia");
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(folderPath);
StorageFile textFile = await folder.GetFileAsync("Warehouse.xml");
await FileIO.WriteTextAsync(textFile, str);
使用 varfolderPath = Path.Combine(Application.persistentDataPath);
使用 xmlDoc.Save(path);
保存文件效果很好。但我无法做到这一点,因为 Vuforia 只能访问 StreamingAssets 中的图像目标(对吗?)。那么有谁知道我做错了什么,我该怎么做才能访问 StreamingAssets 文件夹或更改 Vuforia 使用的文件夹所在的位置?
最佳答案
在 HoloLens 上我也遇到了麻烦。
您可能想尝试 StreamWriter.WriteAsync
与 File.Open(string, FileMode, FileAccess, FileShare)
结合.
在我看来,HoloLens 需要带有 FileMode.Open 的 File.Open
, FileAccess.Write和 FileShare.Write .
我还建议使用 Path.Combine(string, string, string)
类似的东西
var filePath = Path.Combine(Application.streamAssetsPath, "Vuforia", "Warehouse.xml");
using(var fileStream = File.Open(filePath, FileMode.Open, FileAccess.Write, FileShare.Write))
{
using (var writer = new StreamWritet(fileStream))
{
await writer.WriteAsync(textFile);
}
}
这在过去通常对我有用。
但请注意,老实说,我从未尝试过从构建中写入 streamingAssetsPath
,仅在编辑器脚本的 UnityEditor 中写入。并且仅构建持久数据路径。 流媒体资源可能在构建的应用程序中是只读的。
在智能手机上输入,因此没有保修,但我希望这个想法能清楚
关于c# - 如何从我的 Hololens 中编辑 Streamingassets 中的 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56041380/