Thread.currentThread().getContextClassLoader().getResourceAsStream("myConfig.xml"));//在src下寻找myConfig.xml
private String getPath(){
// URL url= Config.class.getResource("config.xml");//也行
URL url=Thread.currentThread().getContextClassLoader().getResource("com/wbq/dom4j/config.xml");//也行
String string=url.getPath();
try {
string=URLDecoder.decode(string, "UTF-8");//解决有中文的路径问题
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return string;
}