繁体   English   中英

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

[英]FileNotFoundException reading JSON file from Assets folder in Windows Store app

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

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

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);

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

我也试过这个

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

同样的错误。 System.IO.FileNotFoundException

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

我的Assets文件夹的屏幕截图

Build Action下的文件属性(右键单击和属性)中,您是否确保将其选为内容 还要确保将“ 复制到输出目录”设置为“始终复制” 这应该可以为你解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM