import java.io.*;public class TestCatchExceptions {
public static void main(String[] args){
  FileInputStream in=null;
  try{
  in=new FileInputStream("Cat.java");   int b=in.read();
  while(b!=-1)
  {System.out.println((char)b); 
  b=in.read();}
  }catch(FileNotFoundException e){
  e.printStackTrace();
  }catch(IOException e){
  System.out.println(e.getMessage());
  }finally{
  try{in.close();
  }catch(IOException e)
  {e.printStackTrace();}}
  }
}at java.io.FileInputStream.<init>(Unknown Source)
at TestCatchExceptions.main(TestCatchExceptions.java:7)
Exception in thread "main" java.lang.NullPointerException
at TestCatchExceptions.main(TestCatchExceptions.java:18)谢谢~!

解决方案 »

  1.   

    没找到Cat.java这种个文件吧
    你用绝对定位试试
      

  2.   

    是不是你的in.close();
    抛得异常啊?加个判断
    if(in != null)
    in.close();
      

  3.   


          in=new FileInputStream("Cat.java");
          // 这句话没有成功打开Cat.java in为null,估计是路径不对finally{
          try{in.close();// 这儿就出错了
          }catch(IOException e)
          {e.printStackTrace();}}
      }