java 读取配置文件信息

蔚落 2022-06-03 06:41 392阅读 0赞
  1. public class StaticConstant{
  2. static {
  3. Properties properties = new Properties();
  4. InputStream in = null;
  5. try {
  6. String url = StaticConstant.class.getResource("/jdbc.properties").getPath();
  7. in = new FileInputStream(new File(url));
  8. properties.load(in);
  9. String userName= properties.getProperty("username");
  10. String pwd= properties.getProperty("pwd");
  11. }
  12. }

发表评论

表情:
评论列表 (有 0 条评论,392人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Java Properties 类读取配置文件信息

    在我们平时写程序的时候,有些参数是经常改变的,而这种改变不是我们预知的。比如说我们开发了一个操 作数据库的模块,在开发的时候我们连接本地的数据库那么 IP ,数据库名称,表名称