java读属性文件实例

来源:互联网 发布:路小雨知乎 编辑:程序博客网 时间:2024/05/29 02:04



package com.eastcom.first.spark.data.redis;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class PropertiesUtils {private static Properties props = new Properties();static {try {String redisPropertiesFileDir = System.getProperty("user.dir") + File.separator + "config/redis.properties";InputStream in = new FileInputStream(new File(redisPropertiesFileDir));props.load(in);} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}public static String getValue(String key) {return props.getProperty(key);}public static void updateProperties(String key, String value) {props.setProperty(key, value);}}