2
我目前正试图让我的程序将用户定义的CSV文件中的数据输入到JTable中。但是,由于某些原因,它无法正常工作,并且每当我尝试加载或保存文件时,NetBeans都会在调试器中抛出一些异常。如何使用JFileChooser将CSV格式数据输入到JTable中
private void openActionPerformed(java.awt.event.ActionEvent evt)
{
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try {
// What to do with the file, e.g. display it in a TextArea
CSVReader reader = new CSVReader(new FileReader(file.getAbsolutePath()));
List myEntries = reader.readAll();
table (myEntries.toArray());
} catch (IOException ex) {
System.out.println("problem accessing file"+file.getAbsolutePath());
}
} else {
System.out.println("File access cancelled by user.");
}
}
这是我对特定问题的代码。
如何正确使用此功能?