需要捕获异常try {
            FileInputStream fin = new FileInputStream("filename.txt");
       }
        catch (Exception ex) {
            System.out.println("读取文件"+filename+"出错!");
        }

解决方案 »

  1.   

    catch(FileNotFoundException fnfe) {;}一般的话,不要用简单的catch所有的exception因为这样你不会知道发生了什么样的错误。
      

  2.   

    不过在所有的catch语句的最后,还可以加上
    catch(Exception e) { //deal with the exception here }这样能够捕捉到所有上边的catch语句未能捕捉到的Exception