【问题标题】:Windows Store App reading from text fileWindows Store App 从文本文件中读取
【发布时间】:2013-06-14 00:32:33
【问题描述】:

我正在开发 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”的数组列表中 并将 strings(string1, string2, string3) 添加到名为“y”的数组列表中。

感谢您的帮助。问候...

【问题讨论】:

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


    【解决方案1】:

    您可以使用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..
        }
    }
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 2013-11-18
      • 1970-01-01
      相关资源
      最近更新 更多