如何逐行读取的Windows RT的文本文件行? [英] How to read a text file line by line Windows RT?
问题描述
我只是不能找到关于如何阅读在Windows RT文本文件,一行行(适用于Windows 8商店)干净的解释。
i just cant find a clean explanation on how to read a text file, line by line in Windows RT ( for Windows 8 Store).
可以说我有文件夹: MyFolder中/ Notes.txt
和我想从Notes.txt读取数据,并将其添加到字符串数组。
And i want to read the data from Notes.txt and add it to an array of strings.
我如何从文件中读取/写入?我以前使用的StreamReader,但现在是非常混乱。而开发的样本不帮助那么多。
How do i read/write from that file? I was using StreamReader before, but now it is very confusing. And the dev samples dont help that much.
推荐答案
香港专业教育学院设法找到了自己的答案。感谢您的帮助。
Ive managed to find the answer myself. Thanks for the help.
// READ FILE
public async void ReadFile()
{
// settings
var path = @"MyFolder\MyFile.txt";
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
// acquire file
var file = await folder.GetFileAsync(path);
var readFile = await Windows.Storage.FileIO.ReadLinesAsync(file);
foreach (var line in readFile)
{
Debug.WriteLine("" + line.Split(';')[0]);
}
}
MyFile.txt的有:
MyFile.txt has:
Test1的;内容描述;
Test1;Description1;
Test2的;内容描述;
Test2;Description2;
//输出对于ReadFile的()
//Output for ReadFile()
测试1
Test2的
这篇关于如何逐行读取的Windows RT的文本文件行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!