How to read file (Metro/WinRT)(如何读取文件 (Metro/WinRT))
问题描述
我对这个看似简单的任务的明显复杂性感到非常震惊.我知道我必须使用 StorageFile
类,并且我发现了这个 示例,但我只想读取一个我知道路径的文件,并将其数据作为文本读取到字符串中.
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
和 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-how-to-read-files-in-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;
}
这篇关于如何读取文件 (Metro/WinRT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何读取文件 (Metro/WinRT)
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30