【发布时间】:2023-03-12 18:49:01
【问题描述】:
可能重复:
Why do I get the “Unhandled exception type IOException”?
我正在尝试使用以下算法求解 Euler #8。问题是,每当我修改有巨大注释的行时,错误Unhandled Exception Type IOException 就会出现在我用注释//### 标记的每一行上。
private static void euler8()
{
int c =0;
int b;
ArrayList<Integer> bar = new ArrayList<Integer>(0);
File infile = new File("euler8.txt");
BufferedReader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(infile), //###
Charset.forName("UTF-8")));
while((c = reader.read()) != -1) { //###
char character = (char) c;
b = (int)character;
bar.add(b); /*When I add this line*/
}
reader.close(); //###
}
【问题讨论】:
-
阅读Exceptions Tutorial,然后使用该知识将代码包装在 try/catch 中或抛出异常——您的选择。
标签: java file-io io ioexception