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

 空白画叶子 发布于 2023-02-05 11:20

我正在尝试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文件夹的屏幕截图:

我的Assets文件夹的屏幕截图

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

    2023-02-05 11:21 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有