public class ServerProperties {
public String url;
public static Properties props = new Properties();
public ServerProperties(){
try{
props.load(this.getClass().getResourceAsStream("Db.properties"));
url=props.getProperty("driverurl");
}catch(Exception e){
System.out.println(e);
Log.writelog("300",e.toString());
}
}
这是我写的类,如果建main函数的类,可以加载。但如果用tomcat不用jdk起动时props.load(this.getClass().getResourceAsStream("Db.properties"));
就无法加载了,在这步时出现空指针异常!请问谁遇见过这个问题!
public String url;
public static Properties props = new Properties();
public ServerProperties(){
try{
props.load(this.getClass().getResourceAsStream("Db.properties"));
url=props.getProperty("driverurl");
}catch(Exception e){
System.out.println(e);
Log.writelog("300",e.toString());
}
}
这是我写的类,如果建main函数的类,可以加载。但如果用tomcat不用jdk起动时props.load(this.getClass().getResourceAsStream("Db.properties"));
就无法加载了,在这步时出现空指针异常!请问谁遇见过这个问题!
解决方案 »
- 关于运行时异常的处理机制
- 求关于打开文件夹的处理方法
- 请教logger.info与System.out.print的区别?它们都分别应用在什么情况下?
- 查看JVM自己自动启动的多线程,关于垃圾收集器
- <<core java>>(7th edition) p42 字条警告处的例子"例如,1<<35与1<<3或8是相同的." 我写了个验证程序,怎么输出结果不同?
- jacob的包操作word一直没有能成功过,帮帮我吧
- Thinking in Java 讨论区
- 最最初级的问题,刚学java,不知道用什么编辑器好??
- 求大牛,反射编译问题(100分给一人)
- 请教,在什么情况下要把interface声明成abstract
- 将TOMCAT这些开源软件进行商业用途的传播,会不会涉及到有侵犯版权的问题
- 求助关于套接字连接!在线
将文件放在classes目录下就行了
写成这样也是到了这句就报异常
props.load(new FileInputStream("Db.properties"));