按key读取properties文件中的value
public static String readSystemConfig(String key){ Properties prop = new Properties(); String value = null; try { InputStream inputStream = new FileInputStream(FilePath); prop.load(inputStream); value = prop.getProperty(key); inputStream.close(); } catch (Exception e) { logger.error("读取配置文件出错",e); } return value.trim(); }
按key写入properties文件内容
public static void writePropertiesInfo(String key,String value) { Properties prop = new Properties(); try { FileInputStream in = new FileInputStream(FilePath); prop.load(in); in.close(); prop.setProperty(key, value); FileOutputStream out = new FileOutputStream(FilePath); prop.store(out, "Conmments"); out.flush(); out.close(); } catch (Exception e) { logger.error("配置文件写入取错误" + e); } }