TestProperty.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:spring-cloud-config-support 作者:
@Test
public void testWithPropertiesFile() throws Exception {
    PropertiesFactoryBean pfb = new PropertiesFactoryBean();
    FileSystemResource pathResource = new FileSystemResource("test.properties");
    File file = pathResource.getFile();
    if (!file.exists()) {
        file.createNewFile();
    }
    System.out.println("pathResource:" + pathResource.getPath());
    System.out.println("pathResource:" + pathResource.getFile());
    pfb.setLocation(pathResource);
    pfb.afterPropertiesSet();
    Properties props = (Properties) pfb.getObject();
    System.out.println(props.get("a"));
    props.setProperty("a", "DDD");
    System.out.println(props.get("a"));
    FileOutputStream oFile = new FileOutputStream(pathResource.getFile());
    props.store(oFile, "Comment");
    oFile.close();
    file.deleteOnExit();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号