Properties theProps = new Properties();
String fileName = "D:\\Tomcat 5.0\\webapps\\myweb\\WEB-INF\\classes\\system.properties";
theProps.load(new FileInputStream(new File(fileName)));
建议用相对路径
"/"是根目录,就是D:\Tomcat 5.0\webapps\myweb\WEB-INF
String fileName = "D:\\Tomcat 5.0\\webapps\\myweb\\WEB-INF\\classes\\system.properties";
theProps.load(new FileInputStream(new File(fileName)));
建议用相对路径
"/"是根目录,就是D:\Tomcat 5.0\webapps\myweb\WEB-INF
java.io.Reader.<init>(Reader.java:61)
java.io.InputStreamReader.<init>(InputStreamReader.java:80)
java.util.Properties.load(Properties.java:266)
org.apache.jsp.test2_jsp._jspService(test2_jsp.java:63)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service
还是路径的问题,你可以先用程序新建文件,看看用哪个路径建出来的文件和你现在的文件在同一目录下,然后把路径copy过来
Properties theProps = new Properties();
String fileName = "/";//java.io.InputStream is = getClass().getResourceAsStream(fileName);
FileInputStream is = new FileInputStream(fileName);boolean b=(is==null);
out.println("<br>is是否为空 : "+b);
out.println("<br>");if (is!=null){
theProps.load(is);
out.println(theProps.getProperty("url"));
}这样is不为空了,但是读出来的属性值为null
为什么?
配置文件的内容如下:drivers=com.microsoft.jdbc.sqlserver.SQLServerDriverdefaultPool.url=jdbc:microsoft:sqlserver://spring:1433;DatabaseName=ComDB
defaultPool.user=sa
defaultPool.password=sa
defaultPool.maxconn=100
java.io.InputStream is = getClass().getResourceAsStream(fileName);getClass().getResourceAsStream()是谁的方法,应该怎么用啊?
这个按道理也应该可以用的,但是路径好象和一般地不同
getClass()这个方法是Object类里面的,所以任何类里面都可以调用
String fileName = "D:\\Tomcat 5.0\\webapps\\ComDB\\WEB-INF\\system.properties";
//InputStream is = getClass().getResourceAsStream(fileName);
FileInputStream is = new FileInputStream(fileName);boolean b=(is==null);
out.println("<br>is是否为空 : "+b);
out.println("<br>");if (is!=null){
theProps.load(is);
out.println(theProps.getProperty("defaultPool.maxconn"));
}又改了!!
这样就没问题了.但是 改成这样 fileName = "system.properties";
就不行,给出的不是tomcat错误;
是"找不到服务器或发生 DNS 错误"
怎么搞的?
java.io.InputStream is = getClass().getResourceAsStream(fileName);弄好了
这样.结帖!