java.io.FileNotFoundException:db.properties(系统找不到指定的路径)



我已经编写了一个基本的jsp代码,用于存储和检索数据库中的数据。在此之前,我正在检查用户的验证。

当我点击提交按钮时,它将重定向到我的jsp页面。

我已经单独编写了一个db.properties文件。

当我给出读取属性文件的完整路径时。,程序执行良好。(这并不是像下面这样硬编码的最佳方式)。

FileInputStream in=新的FileInputStream("C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ServiceDisplay\db.properties");

但当我只指定"db.properties"时,比如(FileInputStream in=新的FileInputStream("db.properties");)程序没有执行,我得到文件未找到异常

请注意,此属性文件仅在当前工作目录中。(即,我的db.properties文件和jsp文件位于ServiceDisplay

我试图将文件名更改为"//db.properties"、"/db.properties"、"./db.properments"、"\db.properties"、.\db.properties、../db.properties"、"。。\db.properties"。但我仍然得到java.io.FileNotFoundException:db.properties

文件"ServiceDisplay\db.properties"位于资源目录中,要加载此文件,必须使用getResoursceAsStream。下面的代码示例:

 ServletContext context = request.getSession().getServletContext();
 InputStream is = context.getResourceAsStream("/db.properties");

最新更新