java解析.properties的配置文件
admin 发布于:2009-07-20 22:57:00
阅读:loading
db.properties
driver:com.microsoft.jdbc.sqlserver.SQLServerDriver##这里的dirver:也可以换成是=,如果是=的话,后面又有:就得用\转义
url:jdbc:microsoft:sqlserver://localhost:1433;
username:sa
password:
***********************************************************************
public void getFile(String fileName) {
Properties prop = new Properties();
InputStream in = getClass().getResourceAsStream(fileName);
if (in != null)
try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
} finally {
in.close();
}
System.out.println(prop.getProperty("driver"));
System.out.println(prop.getProperty("url"));
System.out.println(prop.getProperty("username"));
System.out.println(prop.getProperty("password"));
}
点赞