2种方法。注意只有在运行单元测试的时候才读取test目录下的文件

 

AppTest.class.getResource("/example.xml");

AppTest.class.getClassLoader().getResource("example.xml");

 

相关文章: