如何在Windows Phone 8.1中读取嵌入的文本文件?
本文关键字:文本 文件 读取 Windows Phone | 更新日期: 2023-09-27 18:06:59
(我可以找到许多Windows Phone 7的答案,可能适用于Windows Phone 8/8.1 Silverlight,但不适用于Windows Phone [Store] 8.1)
在测试我的应用程序时,我想使用虚拟服务器响应。由于包含引号的数据量很大,所以我不想使用常量字符串,并且必须转义所有内容。
我怎么读一个文本文件,包含在我的Windows Phone 8.1应用程序?
在这个例子中,我有一个名为sample-response.txt
的文件,它的'Build Action'属性被设置为'Content'。
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("sample-response.txt");
var contents = await Windows.Storage.FileIO.ReadTextAsync(file);
如果你想再次检查它是否被读取ok
Debug.WriteLine(contents);