我正在尝试从我的 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
。我已经两次和三次检查文件是否在 Assets 文件夹中,并且我的路径中没有拼写错误。
这个我也试过
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/resources.json"));
同样的错误。 System.IO.FileNotFoundException
我的 Assets 文件夹的屏幕截图:
最佳答案
在构建操作下的文件属性(右键单击和属性)中,您是否确定将其选为内容?还要确保将复制到输出目录 设置为始终复制。我认为这应该可以解决您的问题。
关于c# - FileNotFoundException 从 Windows 应用商店应用程序的 Assets 文件夹中读取 JSON 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20993849/