日期:2014-05-20 浏览次数:20749 次
private static String username = null;
private static String password = null;
private static String url = null;
static {
String path = JdbcUtils.class.getClassLoader().getResource("db.properties").getPath();
Properties properties = new Properties();
try {
properties.load(new FileInputStream(path));
String driverClass = properties.getProperty("driver");
username = properties.getProperty("username");
password = properties.getProperty("password");
url = properties.getProperty("url");
} catch (Exception e) {
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
Properties p = new Properties();
//加载属性文件,注意路径为当前类目录下
p.load(this.getClass().getResourceAsStream("hello.properties"));
p.get("hi");//获取值