如何阅读在Windows Phone 8.1的嵌入文本文件? [英] How do I read an embedded text file on Windows Phone 8.1?

查看:95
本文介绍了如何阅读在Windows Phone 8.1的嵌入文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我可以找到Windows Phone 7的许多答案这可能合作的Windows Phone 8 / 8.1的Silverlight,但不适用于Windows Phone的[存储] 8.1)

(I can find many answers for Windows Phone 7 which probably work Windows Phone 8/8.1 Silverlight, but not for Windows Phone [Store] 8.1)

虽然测试我的申请,我想用一个虚拟服务器响应。因为它是一个大量包含引号的数据,我不想使用常量字符串,并有逃跑的一切。

While testing my application, I want to use a dummy server response. Since it's a large amount of data that includes quotation marks, I don't want to use a constant string and have to escape everything.

我怎样才能读取文本文件这是包含在我的Windows Phone 8.1的应用程序?

How can I read a text file that's included with my Windows Phone 8.1 application?

推荐答案

在这个例子中,我有一个名为样本-response.txt 及其生成操作属性设置为内容。

For this example, I have a file called sample-response.txt and its 'Build Action' properties is set to 'Content'.

var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("sample-response.txt");
var contents = await Windows.Storage.FileIO.ReadTextAsync(file);



如果你想仔细检查,它的读取确定

and if you want to double-check that it's been read ok

Debug.WriteLine(contents);

这篇关于如何阅读在Windows Phone 8.1的嵌入文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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