public void populateNotesFromFile()
{
try{
BufferedReader reader = new BufferedReader(new FileReader(DEFAULT_NOTES_SAVED));
String fileNotes = reader.readLine();
while(fileNotes != null){
notes.add(fileNotes);
fileNotes = reader.readLine();
}
reader.close();
}
catch (IOException e){
System.err.println("The desired file " + DEFAULT_NOTES_SAVED + " has problems being read from");
}
catch (FileNotFoundException e){
System.err.println("Unable to open " + DEFAULT_NOTES_SAVED);
}
//make sure we have one note
if (notes.size() == 0){
notes.add("There are no notes stored in your note book");
}
}
Run Code Online (Sandbox Code Playgroud)
每当我编译上面的时候,我都会收到一条消息,说找不到符号类IOException e
有人可以告诉我如何解决它:d
谢谢
如果我们要捕捉特定形式IOException
或任何其他类型的事实,我们只会尝试捕捉一对(并为他们定义确定的输出)说
FileNotFoundException
ZipException
我们是否应该总是将它追上并覆盖所有基地
catch(IOException e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
然后可能更进一步捕捉Exception e
,或者这是完全浪费时间?
我在第一年结束时从事计算机科学工作,并且想要搞一些基本的东西.我想使用线程,所以我可以学习.
有什么好的例子可供学习?