我试图允许用户指定用于生成ArrayList的文件的路径,然后使用通过TextBox输入的文本(字符串格式为@)将其用于图表。 C:\ filename.csv“以前在路径被硬编码时使用和工作的”。但是,每次执行代码时,我都会收到一个未处理的参数异常错误。我该如何解决此错误?
private ArrayList readData()
{
logFile = textFilePath.Text;
// initialise an array list for storing the data
ArrayList logData = new ArrayList();
// read every line in the file
using (StreamReader reader = new StreamReader(logFile))
{
string line;
while ((line = reader.ReadLine()) != null)
{
// split the line into a string array using the comma
// delimiter and add to the array list
string[] parts = line.Split(',');
logData.Add(parts);
}
}
// strip the first element from our array list, as this contains
// the header information from our file
logData.RemoveAt(0);
// return the array list containing the file contents
return logData;
}