我有读文件,StreamReader
同时line != null
添加到一个问题textBox1
C#从文件中读取符合的StreamReader与DownloadFileAsync
代码:
using(StreamReader reader = new StreamReader("lastupdate.txt"))
{
string line;
while((line = reader.ReadLine()) != null)
{
textBox1.Text = line;
}
reader.Close();
}
它不工作,我不知道为什么。我试图使用using StreamReader
,我从URL下载文件,我可以在文件夹中看到该文件已下载。 lastupdate.txt
大小为1KB。
这是我目前使用的代码MessageBox
。如果我删除MessageBox
,代码不起作用。它需要某种等待或我不知道:
WebClient client = new WebClient();
client.DownloadFileAsync(new Uri(Settings.Default.patchCheck), "lastupdate.txt"); // ok
if(File.Exists("lastupdate.txt"))
{
MessageBox.Show("Lastupdate.txt exist");
using(StreamReader reader = new StreamReader("lastupdate.txt"))
{
string line;
while((line = reader.ReadLine()) != null)
{
textBox1.Text = line;
MessageBox.Show(line.ToString());
}
reader.Close();
}
File.Delete("lastupdate.txt");
}
textBox1.Text = text? textBox1.Text + =行? – shenhengbin 2012-02-24 14:13:26
你确定,虽然被执行,读者有价值吗? – Akrem 2012-02-24 15:47:10
你是什么意思? lastupdate.txt包含数据“1”只是数字... – user1085907 2012-02-24 16:15:18