我在从文本文件(记事本 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
}
}