classLoader.getResources怎么不能返回资源?

theoffspring 2011-09-01 03:55:35

package mytest;

import java.net.URL;
import java.util.Enumeration;

public class TestGetResources {
public static void main(String[] args) throws Exception {

Enumeration<URL> urls= getClassLoader().getResources("/config1/1.xml");

while (urls.hasMoreElements()){
URL url=urls.nextElement();
System.out.println(url.getFile());
}
}

private static ClassLoader getClassLoader() throws Exception{
// return TestGetResources.class.getClassLoader();
return Thread.currentThread().getContextClassLoader();
}
}

/config1/1.xml这个明明是存在的,编译后类路径中也可以看到它,为什么执行的时候,返回结果是空呢?
...全文
285 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
theoffspring 2011-09-01
  • 打赏
  • 举报
回复
见鬼了,一开始也试过开头不用/,结果不好用。
huntor 2011-09-01
  • 打赏
  • 举报
回复
cofig1/1.xml

62,614

社区成员

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

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