做ssb项目时自己做的properties操作工具类

本文介绍了一个简单的Properties工具类实现,包括通过key获取value的方法及更新文件内键值对的方法。该工具类使用Java语言编写,提供了加载配置文件、读取配置项及修改配置项的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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文件异常");
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值