相关疑难解决方法(0)

FileNotFoundException从Windows应用商店应用中的Assets文件夹中读取JSON文件

我正在尝试json从我的Assets文件夹中读取文件.我尝试了很多代码示例,并且所有代码都是相同的.

我觉得我必须做一些愚蠢的事情,但我无法看到它.

string filepath = @"Assets\resources.json";
StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await folder.GetFileAsync(filepath); // error here
var data = await Windows.Storage.FileIO.ReadTextAsync(file);
Run Code Online (Sandbox Code Playgroud)

每次我运行上面的代码,我得到一个System.IO.FileNotFoundException我的应用程序.我已经加倍并三倍检查文件是在资源文件夹中,并且我的路径中没有拼写错误.

我也试过这个

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/resources.json"));
Run Code Online (Sandbox Code Playgroud)

同样的错误. System.IO.FileNotFoundException

我的Assets文件夹的屏幕截图:

我的Assets文件夹的屏幕截图

c# windows file-io windows-runtime windows-store

11
推荐指数
1
解决办法
4076
查看次数

标签 统计

c# ×1

file-io ×1

windows ×1

windows-runtime ×1

windows-store ×1