一、如果将properties文件保存在src目录下

1.读取文件代码如下:

/**
* 配置文件为settings.properties
* YourClassName对应你类的名字
*
/ 
private Properties LoadSettings() {
        Properties prop = new Properties();
        
        try {
            InputStream  in = new BufferedInputStream(YourClassName.class.getClassLoader().getResourceAsStream("/settings.properties"));
            prop.load(in); 
            in.close();
        } catch (Exception e) {
            System.err.println("Load settings.properties file Error! :\r\n"+ e.getMessage());
            prop = null;
        }
        
        return prop;
    }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-23
  • 2021-12-19
  • 2021-05-19
  • 2022-01-16
相关资源
相似解决方案