获得项目中资源文件的路径

public class PasswordTest extends BaseTest {
	
	
	@Test
	public void getPath(){
		java.net.URL resource = BaseTest.class.getClassLoader().getResource("chp5/chp5Ehcache.xml");
		System.out.println("getPath");
		String path = PasswordTest.class.getClassLoader().getResource("chp5/chp5Ehcache.xml").getPath();
		System.out.println(path);///E:/Eclipse_workspace/ShiroLearn/build/classes/chp5/chp5Ehcache.xml 空格会被%20代替 用String decodePath = URLDecoder.decode(path, "utf-8");能得到真正的带空格的路径
	}
}//不直接在classpath底下的文件要加上包名路径

猜你喜欢

转载自2018scala.iteye.com/blog/2231917