关于classLoader getResourceAsStream的一个问题 急需解决
我在用classLoader。getResourceAsStream("config.xml")时, 参数的路径我怎么设置都不对
具体的情况见下代码,不知道错在哪里,请高手指点:
public load(String filename) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = this.getClass().getClassLoader();
}
ConfigLoader configLoader = new ConfigLoader();
String loc = "/" + filename;
InputStream in = classLoader.getResourceAsStream(loc);
if (in == null) {
loc = filename;
in = classLoader.getResourceAsStream(loc);
}
if (in == null) {
loc = filename;
in = classLoader.getResourceAsStream("./"+loc);
}
if (in == null) {
loc = filename;
in = classLoader.getResourceAsStream("cn/com/"+loc);
}
if (in == null) {
loc = "/META-INF/" + filename;
in = classLoader.getResourceAsStream(loc);
}
if (in == null) {
loc = "META-INF/" + filename;
in = classLoader.getResourceAsStream(loc);
}
if (in == null) {
loc = "/META-INF/default.xml";
in = classLoader.getResourceAsStream(loc);
}
if (in == null) {
loc = "META-INF/perm-default.xml";
in = classLoader.getResourceAsStream(loc);
}
if (logger.isDebugEnabled()) {
logger.debug("正在读取初始化配置文件: " + loc);
}
if (in == null) {
throw new UserManagerImplementationException("配置文件" + filename + "不存在!");
}
}