public class PropertiesUtil { //通过key获取value public static String getValue(String filePath,String key) throws SSBangException { InputStream in = null; Properties prop = new Properties(); try { in = new FileInputStream(filePath); prop.load(in); String value = prop.getProperty(key); in.close(); return value; }catch (Exception e){ System.out.println("properties工具类getValue问题"); throw new SSBangException("读取properties文件异常"); } } //更新文件内的键值对 public static int setValue(String filePath,String key,String value) throws SSBangException { FileOutputStream out = null; Properties prop = new Properties(); try { FileInputStream in = new FileInputStream(filePath); prop.load(in); in.close(); prop.setProperty(key,value); out = new FileOutputStream(filePath,false); prop.store(out,"update "+key+" to "+value+""); out.close(); RewardConstant.updateRewardSetting(); System.out.println(RewardConstant.minAmount+"---"+RewardConstant.maxAmount); TaobaoConstant.getProperty(); System.out.println(TaobaoConstant.APP_KEY+"==="+TaobaoConstant.ADZONE); return 1; }catch (Exception e){ System.out.println("properties工具类setValue问题"); throw new SSBangException("写入properties文件异常"); } } }
做ssb项目时自己做的properties操作工具类
最新推荐文章于 2024-07-02 00:09:28 发布