java 使用.properties文件存储和取用数据
@Test
public void setProperties() throws Exception{
Properties pro = new Properties();
OutputStream proos = new FileOutputStream("src/main/java/resources/xx.properties");
pro.setProperty("apiKey","eyJ0eXAiOiJVudC4xI3CmtoK5z1g");
pro.store(proos,"xxxx");
proos.close();
}
@Test
public void getProperties() throws Exception{
Properties pro = new Properties();
InputStream prois = new FileInputStream("src/main/java/resources/xx.properties");
pro.load(prois);
String apiKey = (String) pro.get("apiKey");
System.out.println(apiKey);
prois.close();
}