Java error: Default constructor cannot handle exception type FileNotFound Exception

前端 未结 3 1587
醉话见心
醉话见心 2021-01-01 07:04

I\'m trying to read input from a file to be taken into a Java applet to be displayed as a Pac-man level, but I need to use something similar to getLine()... So I searched fo

3条回答
  •  再見小時候
    2021-01-01 07:47

    You need to surround your code with try and catch as follows:

    try {
        File inFile = new File("textfile.txt");
        FileInputStream fstream = new FileInputStream(inFile);//ERROR
    } catch (FileNotFoundException fe){
        fe.printStackTrace();
    }
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    

提交回复
热议问题