
private void getUser(String tmpfile){
Properties props = new Properties();
props.load(DbTask.class.getClassLoader().getResourceAsStream(
tmpfile));
return props.getProperty("user");
}
方法说明:
tmpfile是传入的需要读取的文件名
这个文件一定要跟DbTask类,在一个包下面
调用:
getUser("/test.ini"); ==>abc
test.ini文件内容:
user=abc
pwd=123
如果不在同一个包中,那么只要把 getUser("/test.ini");改成 getUser("/包/test.ini"); ==> eg. getUser("/cn/test/sample/test.ini");