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.");
}
}
這是我對特定問題的代碼。
如何正確使用此功能?