java 加載properties 文件

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()//表示當前包中的文件


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章