我在写一个读取csv文件并将内容显示到JList的小应用程序。尝试读取文件时获取java.io.FileNotFoundException
我目前的问题是,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());'这应该给出一个很好的暗示问题是什么。它可能是“权限被拒绝”,或者“系统找不到指定的文件”或其他内容。这可能会提供有趣的信息,而不是人们对问题的可能性进行猜测。 –