public static String mysql_url;
public static String mysql_uname;
public static String mysql_passwd;
static{
Properties properties = new Properties();
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/org/hzy/config/datasource.properties");
try {
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
mysql_url=properties.getProperty("url");
mysql_uname=properties.getProperty("uname");
mysql_passwd=properties.getProperty("passworld");
System.out.print(properties.getProperty("initialContextfactory"));
System.out.print(properties.getProperty("providerURL"));
System.out.print(properties.getProperty("dataSource"));
}
getClass().getClassLoader().//默认的是src文件夹下
getClass()//表示当前包中的文件
转自:http://www.cnblogs.com/andysd/archive/2012/09/21/2697515.html