如何读取文件(城域/ WinRT的) [英] How to read file (Metro/WinRT)

查看:105
本文介绍了如何读取文件(城域/ WinRT的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个看似简单的任务明显的复杂性相当震惊。我知道我必须使用 StorageFile 类,我发现这个的example ,但我只是想读一个单一的文件,而我知道路径,阅读它的数据作为文本字符串。

I'm quite astounded by the apparent complexity of this seemingly simple task. I know that I have to use the StorageFile class, and I've found this example, but I just want to read one single file, to which I know the path, and read it's data as text into a string.

从我已经能够收集,阅读与 StorageFile 的文件,我必须要经过一堆接口; IAsyncOperation< StorageFile方式> IAsyncOperationCompletedHandler

From what I've been able to gather, to read a file with StorageFile, I have to go through a bunch of interfaces; IAsyncOperation<StorageFile> and IAsyncOperationCompletedHandler.

有一定是一个更好的(简单)的方式。是这样的:

There must be a better (simpler) way. Something like:

using (StorageFile sf = StorageFile.OpenAsync("myFile.txt"))
{
    string line = sf.ReadLine();
}



显然,这并不工作,但也许我错过了什么,或?有人能向我解释如何阅读方式不同的文件

Obviously this doesn't work, but maybe I've missed something, or someone could explain to me how to read a file in a different way?

推荐答案

该网页可能会有所帮助:的 http://blog.jerrynixon.com/2012/06/windows -8-如何阅读,文件正在winrt.html

This web page might be helpful: http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html

相关代码:

public string CurrentFileBuffer
{
    get; private set;
}

public async void ReadTextFile(string Path)
{
    var folder = Package.Current.InstalledLocation;
    var file = await folder.GetFileAsync(Path);
    var read = await FileIO.ReadTextAsync(file);
    CurrentFileBuffer = read;
}

这篇关于如何读取文件(城域/ WinRT的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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