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)


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01