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");



相关文章:

  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
相关资源
相似解决方案