Windows Store App从文本文件中读取

时间:2013-06-13 16:17:48

标签: c# windows-8 windows-store-apps

我正在开发Windows应用商店。我有这个文本文件名为:text.txt

account1 string1
account2 string2
account3 string3

这个c#代码:

private async void Page_Loaded(object sender, RoutedEventArgs e)
{
    var path = "text.txt";
    var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
    try
    {
        var file = await folder.GetFileAsync(path);
    }
    catch (FileNotFoundException)
    {
        test.Text = "error";
    }
}

代码可以找到没有问题的文本文件。但我无法读懂它。我想从文本文件中读取帐户名称(account1,account2,account3),并将其添加到名为" x"的arraylist中。 并将字符串(string1,string2,string3)添加到名为" y"的arraylist中。

我很感激你的帮助。此致...

1 个答案:

答案 0 :(得分:3)

您可以使用ReadLinesAsync将文件读入字符串集合:

try
{
    var file = await folder.GetFileAsync(path);
    var lines = await FileIO.ReadLinesAsync(file);
    foreach (string line in lines)
    {
        // "line" variable should contain "account(x) string(x)"
        // You can then parse it here..
    }
}
...
相关问题