用下面这个程序读一下试试。db.properties文件放置在\classes目录下测试环境jdk1.4import java.util.ResourceBundle;public class EnvPara
{
private static ResourceBundle resources = null; public static void init()
{
if(resources == null)
{
resources = ResourceBundle.getBundle("db");
}
} public static String getString(String sName)
{
String sResult = null;
try
{
init();
sResult = resources.getString(sName);
}
catch(Exception e)
{
e.printStackTrace();
sResult = null;
}
return sResult;
} public static void main(String[] args)
{
System.out.println("test:"+EnvPara.getString("driver"));
}
}

解决方案 »

  1.   

    肯定是读的不是你需要的文件,建议你搜一下同名文件。或者你给出绝对路径看看。这种问题是读错了文件,不是API错误。
      

  2.   

    上面的代码好像没什么问题,再试试这个.
    Properties prop=new Properties();
          try{
            InputStream is=getClass().getResourceAsStream("db.properties");
            prop.load(is);
            if(is!=null){
              is.close();
            }
          }catch(IOException e){      }
          this.sDBDriver=prop.getProperty("driver");
          this.sConnStr=prop.getProperty("url");
          this.username=prop.getProperty("user");
          this.password=prop.getProperty("password");
        }
      

  3.   

    我是在jb中建的工程,资源文件和.java放在同一目录下,然后指定当前路径(直接写文件名)应该没错吧!再试试..