我在项目A中的Student类中写了
public void show(){File targetFile = new File(Student.class.getResource("/").getPath()+“com/enum.xml”);
...
}然后在项目B引用项目A。在项目B中的Person类中写了
public void test(){
  Student stu = new Student();
  stu.show();
}
调用test方法就抛异常 java.io.FileNotFoundException: 
F:\javawork\ads-report-biz\bin\com\type\enum.xml (系统找不到指定的路径。)

解决方案 »

  1.   

    你把:Student.class.getResource("/").getPath()输出一下看看是什么路径,这个得到的是你的Java文件变成成class文件的目录,一般的是bin目录(看看你的bin/com/enum.xml有么),
    你可以把得到的路径处理一下…
      

  2.   

    Are you 确定你的路径是对的?
      

  3.   

    F:\javawork\ads-report-biz\bin\com\type\enum.xmlFile targetFile = new File(Student.class.getResource("/").getPath()+“com/enum.xml”);
    上面这两个路径明显不一样, \com\type\enum.xml  和 getPath()+“com/enum.xml”, 你再检查一下看看
      

  4.   

    3L说的没错。win和linux 的文件路径分隔符不一样。把com/enum.xml换成win的/
    当然,如果为了跨平台,还是先获取下系统属性的文件分隔符
    System.getProperties().list(System.out);打出来 看看分隔符是什么。
      

  5.   

    File targetFile = new File(Student.class.getResource("/").getPath()+“com/enum.xml”);路径打印出来 就知道了