我正在尝试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);
每次我运行上面的代码,我得到一个System.IO.FileNotFoundException
我的应用程序.我已经加倍并三倍检查文件是在资源文件夹中,并且我的路径中没有拼写错误.
我也试过这个
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/resources.json"));
同样的错误. System.IO.FileNotFoundException
我的Assets文件夹的屏幕截图:
在Build Action下的文件属性(右键单击和属性)中,您是否确保将其选为内容?还要确保将" 复制到输出目录"设置为"始终复制".这应该可以为你解决问题.