[英]Reading a Text File One Line at a Time in Windows 8.1 Application
I added this code to the OnNavigatedTo
function: 我将此代码添加到
OnNavigatedTo
函数中:
int counter = 0;
string line;
string path = "Streams\\Usernames.txt";
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader(path);
while ((line = file.ReadLine()) != null)
{
Lbx_Usernames.Items.Add(line);
counter++;
}
But I keep getting this error: 但我不断收到此错误:
Cannot convert from 'string' to 'System.IO.Steam'
无法从“字符串”转换为“ System.IO.Steam”
First off, there are many differences in the API sets that are used in a desktop application and a Windows 8.1 (Universal) application. 首先,在桌面应用程序和Windows 8.1(通用)应用程序中使用的API集有很多差异。
This 这个
System.IO.StreamReader file = new System.IO.StreamReader(string path);
is only available in desktop applications (Console, WinForm/WPF). 仅在桌面应用程序 (控制台,WinForm / WPF)中可用。
In Windows Store apps , you can use FileIO.ReadLinesAsync(IStorageFile) to read all text from a file, which accepts a StorageFile as an argument, and returns a list of lines and you can iterate through each line. 在Windows Store应用程序中 ,可以使用FileIO.ReadLinesAsync(IStorageFile)从文件中读取所有文本,该文件接受一个StorageFile作为参数,并返回行列表,并且可以循环浏览每行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.