在我的Rwproperties.java 的路径如下,它是专门读取和修改数据库配置文件dbsqlsever.properties
G:\Workspaces\MyEclipse 7.0\MyFirstJSP\src\dbConfig\Rwproperties.java
G:\Workspaces\MyEclipse 7.0\/MyFirstJSP/src/dbConfig/dbsqlsever.properties
上面这两个文件发布到Tomcat6.0中去后,它们的路径变为了下面的路径
D:\Tomcat6.0\webapps\MyFirstJSP\WEB-INF\classes\dbConfig\dbsqlsever.properties.class
D:\Tomcat6.0\webapps\MyFirstJSP\WEB-INF\classes\dbConfig\Rwproperties.class
Rwproperties.java 中有一个函数是getValue(),用来读取dbsqlsever.properties。现在问题就出现在“ InputStream in=new FileInputStream()”的参数,也就是路径不好写。
public void getValue()
{
Properties pro=new Properties();
try {
InputStream in=new FileInputStream("D:\\Tomcat6.0\\webapps\\MyFirstJSP\\WEB-INF\\classes\\dbConfig\\dbsqlsever.properties");
//InputStream in=new FileInputStream("dbsqlsever.properties");
//File file=new File("dbsqlsever.properties");
//System.out.println(file.getAbsolutePath());
//InputStream in=pro.getClass().getResourceAsStream("/dbConfig/dbsqlsever.properties");
//String root=getRealPath("/dbConfig/dbsqlsever.properties");
pro.load(in);
dirver=pro.getProperty("driver");
url=pro.getProperty("url");
username=new String(pro.getProperty("username").getBytes("ISO-8859-1"),"GBK");
password=new String(pro.getProperty("password").getBytes("ISO-8859-1"),"GBK");
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}