可能重复:
Why do I get the “Unhandled exception type IOException”?未处理的异常类型为IOException
我尝试使用下面的算法来解决欧拉#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(); //###
}
阅读[例外教程](http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html),然后利用这些知识要么将代码包装在try/catch中,要么抛出异常 - 您的选择。 –