用下面这个程序读一下试试。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"));
}
}
{
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"));
}
}
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");
}