use properties write to config.properties files

来源:互联网 发布:网络数据包发送工具 编辑:程序博客网 时间:2024/05/22 07:00
//将数据写入到propertiesProperties prop = new Properties();FileOutputStream out = null;try{    String path = this.getClass().getClassLoader().getResource("").getPath();    // 从输入流中读取属性列表(键和元素对)    // 调用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。    // 强制要求为属性的键和值使用字符串。返回值是 Hashtable 调用 put 的结果。    prop.setProperty("sqladdr", sqladdr);    prop.setProperty("sqluser",sqluser);    prop.setProperty("sqlpassword",sqlpassword);    out = new FileOutputStream(path + "/config.properties");    prop.store(out, "save");    // 以适合使用 load 方法加载到 Properties 表中的格式,    // 将此 Properties 表中的属性列表(键和元素对)写入输出流} catch (IOException e) {    logger.error("----read file error---",e);}finally {    if(out != null){        try {            out.close();        } catch (IOException e) {            logger.error("----read file error---",e);        }    }}
1 0
原创粉丝点击