我在项目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 (系统找不到指定的路径。)
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 (系统找不到指定的路径。)
你可以把得到的路径处理一下…
上面这两个路径明显不一样, \com\type\enum.xml 和 getPath()+“com/enum.xml”, 你再检查一下看看
当然,如果为了跨平台,还是先获取下系统属性的文件分隔符
System.getProperties().list(System.out);打出来 看看分隔符是什么。