我有讀文件,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