我遇到了從文本文件(記事本txt文件)中加載數據並將其顯示在列表框中的問題。以下是我的代碼,不知道爲什麼它不加載數據將文本文件中的數據添加到列表框
private void loadData() {
try {
using (StreamReader reader = new StreamReader("visits.txt")) //Reads in file
{
string line;
while ((line = reader.ReadLine()) != null) {
string[] data = line.Split(','); //Splits the lines up when there is a ,
lstDeliveries.Items.Add(data[0] + ", " + data[1] + ", " + data[2]);
lstPickups.Items.Add(data[3] + ", " + data[4]);
}
}
}
catch (FileNotFoundException) {
MessageBox.Show("The file was not found!!"); //Provides error if file not found
Environment.Exit(0); //Closes application
}
}
而問題是... –
您至少可以提供您的問題的描述,即異常消息 – horgh
我沒有任何異常消息 – littledevils326