java文件中读取配置文件的内容

配置文件存放在classpath路径下

 public  String getSalt() throws  Exception{
 //首先获取输入流,使用输入流打开文件
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("aaa.properties");
//将输入流加载到properties,使用properties获取相应的值
        Properties properties = new Properties();
        properties.load(inputStream);
       return properties.getProperty("salt");
    }

你可能感兴趣的:(java)