【发布时间】:2013-02-01 08:26:37
【问题描述】:
我正在编写一个读取 csv 文件并将内容显示到 JList 中的小应用程序。
我目前的问题是new FileReader(file) 代码不断给我一个java.io.FileNotFoundException 错误,我不太清楚为什么。
loadFile.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent actionEvent)
{
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File("~/"));
if (fileChooser.showOpenDialog(instance) == JFileChooser.APPROVE_OPTION)
{
File file = fileChooser.getSelectedFile();
CSVReader reader = new CSVReader(new FileReader(file.getAbsolutePath()));
fileLocation.setText(file.getAbsolutePath());
}
}
});
【问题讨论】:
-
异常的确切信息是什么?
System.out.println(e.getMessage());这应该可以很好地提示问题所在。它可能是“权限被拒绝”,或“系统找不到指定的文件”,或其他。这可能会提供有趣的信息,而不是人们疯狂猜测问题可能是什么。
标签: java swing jfilechooser filenotfoundexception opencsv