找不到符号类IOException

use*_*110 8 java exception

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

谢谢

Pet*_*háč 21

IOException是java.io包中的一个类,因此为了使用它,您应该import在代码中添加一个声明.import java.io.*;(在java文件的最顶部,在包名和类声明之间)

FileNotFoundException 是一个 IOException.这是IOException的特化.一旦捕获到IOException,程序流将永远不会到达检查更具体的IOException的程度.只需交换这两个,首先测试更具体的情况(FileNotFound),然后处理(捕获)任何其他可能的IOExceptions.