public FileReader() throws FileNotFoundException {
//create fileChooser
JFileChooser chooser = new JFileChooser();
//open fileChooser
int returnValue = chooser.showOpenDialog(new JFrame());
try {
if (returnValue == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
}
} catch (FileNotFoundException e) {
}
}
我正在编写一个程序来读取文本文件并将其放入一个字符串(单词)的数组中。这只是程序的文件阅读器,当我尝试从代码的另一部分调用方法时,它给我一个错误。任何想法将不胜感激;它可能是一个简单的修复,我似乎无法找到它。Java使用JFileChooser时未报告的异常
这里的错误:
unreported exception FileNotFoundException; must be caught or declared to be thrown
在哪一行发生? –
实际上,当我在其他地方调用方法时,实际发生这种情况,但这是有问题的代码 – Carl5444