因此,我在读取CSV文件并将其添加到我的链表时遇到了问题。我将csv文件读入到数组、数组列表等内容中,但从未读入过单链表。现在我的问题是,我在解析薪水的代码行上总是得到一个ArrayOutOfBoundsException。代码是我的menu类的一部分,我在其中读取文件并将其添加到链表中。所以我的问题是,如何正确地将csv文件读取到链表中?谢谢!
public class EmpMenu {
private SLList<Employee> list = new SLList<Employee>();
public EmpMenu() {
Scanner inFile = null;
try {
inFile = new Scanner(new File("employees.txt"));
} catch (FileNotFoundException x) {
System.err.print("File not found");
}
while (inFile.hasNextLine()) {
String line = inFile.nextLine();
String[] records = line.split(",[ ]");
String employeeID = records[0];
String fName = records[1];
String lName = records[2];
Double salary = Double.parseDouble(records[3]);
Employee employee = new Employee(employeeID, fName, lName, salary);
list.add(employee);
}https://stackoverflow.com/questions/52570775
复制相似问题