日期:2014-05-18 浏览次数:20953 次
public void delete(){
try {
String path = UserDao.class.getClassLoader().getResource("db.properties").getPath();
System.out.println("文件的路径为:"+path);
FileInputStream in = new FileInputStream(path);
Properties prop=new Properties();
prop.load(in);
String url=prop.getProperty("url");
String username=prop.getProperty("username");
String passwd=prop.getProperty("passwd");
System.out.println("------这是通过传统方式获取的配置文件----------");
System.out.println("url==:"+url+" 用户名="+username+" 密码="+passwd);
} catch (Exception e) {
e.printStackTrace();
}
}
文件的路径为:/D:/Program%20Files/Apache%20Software%20Foundation/Tomcat%205.5/webapps/Servlet/WEB-INF/classes/db.properties
java.io.FileNotFoundException: D:\Program%20Files\Apache%20Software%20Foundation\Tomcat%205.5\webapps\Servlet\WEB-INF\classes\db.properties (系统找不到指定的路径。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at com.java.test.UserDao.delete(UserDao.java:40)
at com.servlet.test.ServletContextCommuncation.doGet(ServletContextCommuncation.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:722)