关于classLoader getResourceAsStream的一个问题 急需解决

thomasqian 2004-09-03 11:16:22
我在用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 + "不存在!");
}
}
...全文
164 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
drzy123 2005-01-17
  • 打赏
  • 举报
回复
InputStream is = getClass().getResourceAsStream("db.properties");
db.properties是一个文件,这句话是什么意思呀?
shouni 2004-09-03
  • 打赏
  • 举报
回复
其实你只要用getClass().getResourceAsStream("/META-INF/perm-default.xml");这样就行

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧