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