FileNotFoundException异常读数从Assets文件夹JSON文件在Windows商店应用 [英] FileNotFoundException reading JSON file from Assets folder in Windows Store app

查看:308
本文介绍了FileNotFoundException异常读数从Assets文件夹JSON文件在Windows商店应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读 JSON 从我的资产文件夹中。我试过无数code的例子,都是同样的事情的变化。

I'm trying to read a json file from my Assets folder. I've tried numerous code examples, and all are variations on the same thing.

我觉得我必须做一些愚蠢的事,但我就是不能看到它。

I feel like I must be doing something stupid, but I just can't see it.

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

我每次运行上面的code我得到一个 System.IO.FileNotFoundException 我的应用程序。我有双重和三倍检查该文件是在资产和文件夹中有我的路径中没有错别字。

Every time I run the above code I get a System.IO.FileNotFoundException on my app. I've double and tripled checked the file is in the assets folder and there are no typos in my path.

我也试过这种

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

同样的错误。 System.IO.FileNotFoundException

我的资产文件夹的截图:

Screenshot of my Assets folder:

推荐答案

在该文件的下的属性(右键点击属性)的生成操作有你确信这个选择为内容?另外,还要确保复制到输出目录设置为复制始终。这应该解决的问题为你我的想法。

In the properties of the file (Right click and properties) under Build Action have you made sure this is selected as Content? Also make sure that Copy to Output Directory is set as Copy Always. This should solve the problem for you I think.

这篇关于FileNotFoundException异常读数从Assets文件夹JSON文件在Windows商店应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆