注意IOException是checked exception.
f.getAbsolutePath()不会抛出IoException, 所以编译的时候不过.
换成catch(Exception e)就可以了.getAbsolutePath()是绝对路径

解决方案 »

  1.   

    getAbsolutePath()
    getCanonicalPath()
    输出结果是一样的啊
      

  2.   

    想确切知道异常的的类型的话,可以先用下面的语句测试一下,再写:
    try
    {
     // Write your code here
    }
    catch(Exception e)
    {
      System.out.println(e.getClass().getName());
    }
    打印出来的是确切的异常的类的名称(包括Package)。