通常用法
InputStream is=getClass().getResourceAsStream("/db.properties")
把db.proerties放在 .....WEB-INF\classes\目录下

解决方案 »

  1.   

    给你个例子(sql.property放在WEB-INF\classes\目录下)
        try{
          //String iconfile=System.getProperty("user.dir");
          in = getClass().getResourceAsStream("/sql.properties");
          props.load(in);
        }
        catch (Exception e) {
                System.err.println("读取sql.properties文件出错"
                    + "in PlatformGlobals");
                e.printStackTrace();
            }
        finally {
           try {
              if (in != null) { in.close(); }
           } catch (Exception e) {}
        }
        if (props != null) {
          sDBDriver = props.getProperty("driver"); //"sun.jdbc.odbc.JdbcOdbcDriver";
          sConnStr = props.getProperty("url"); //"jdbc:odbc:myodbc";
          user = props.getProperty("user");
          password = props.getProperty("password");
          if (sDBDriver ==null || sConnStr ==null || user ==null || password ==null) {
             System.out.println("请检查sql.properties文件设置是否有误");
          }
          else{
            try {
              Class.forName(sDBDriver);
            }
            catch (java.lang.ClassNotFoundException e) {
              System.err.println("mydb(): " + e.getMessage());
            }
          }
        }