如何逐行读取文本文件 Windows RT? [英] How to read a text file line by line Windows RT?

查看:26
本文介绍了如何逐行读取文本文件 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 = @"MyFolderMyFile.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:

测试 1;描述 1;

测试 2;描述 2;

//ReadFile()的输出

//Output for ReadFile()

测试 1

测试 2

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

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