【发布时间】:2022-02-24 08:40:43
【问题描述】:
我正在尝试从为 UWP 构建的统一应用程序加载文件,更具体地为 HoloLens。我有一个可用的 FilePicker
#if !UNITY_EDITOR && UNITY_WSA_10_0
UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
picker.FileTypeFilter.Add(".bytes");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
UnityEngine.WSA.Application.InvokeOnAppThread(() =>
{
string name = (file != null) ? file.Name : "No data";
string path = (file != null) ? file.Path : "No data";
if( file != null )
CaseManager.Instance.ActiveUseCase = new Case(new CaseDataDiscriptor(name, path));
SceneLoader.Instance.LoadSceneAsync("ARViewer");
SceneLoader.Instance.UnLoadScene("CaseList");
}, false);
}, false);
#endif
但是,当尝试在代码的其他部分使用
加载文件时File.ReadAllBytes(filePath);
我得到以下异常,文件的实际文件路径在哪里。正如我之前使用文件选择器选择的那样存在
DirectoryNotFoundException: Could not find a part of the path <MYPATH>.at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0 at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <00000000000000000000000000000000>:0 at System.IO.File.OpenRead (System.String path) [0x00000] in <00000000000000000000000000000000>:0 at System.IO.File.ReadAllBytes (System.String path) [0x00000] in <00000000000000000000000000000000>:0 at Assets.Scripts.Utils.Parser.Parser.FileToByteArray (System.String filePath) [0x00000] in <000000000000000000000
任何帮助将不胜感激
【问题讨论】:
-
Afaik 在 UWP 中你不能直接使用来自
File的任何东西 -
你有解决办法吗?
-
Afaik 你需要通过
FileIO -
你能举个例子,如果想将文件加载为字节[]
-
您可以使用
FileIO.ReadBufferAsync然后简单地使用ToArray参见例如here