package com.common.utils;
import lombok.Data;
import org.apache.log4j.Logger;
import java.io.Serializable;
import java.util.ResourceBundle;
import java.util.Set;
/**
* properties工具类
* @author nahuan
*
*/
@Data
public class MyPropertiesUtils implements Serializable{
private static final Logger logger = Logger.getLogger(MyPropertiesUtils.class.getName());
/**
* 读取文件中单个的key(jdk自带,推荐使用)
* @param proPath 例如:"conf/constant" 其中文件名不带properties后缀
* @param key
* @return
*/
public static String getResourceValue(String proPath,String key) {
ResourceBundle resource = ResourceBundle.getBundle(proPath);
return resource.getString(key);
}
/**
* 读取文件中单个的key(jdk自带推荐使用)
* @param proPath 例如:"conf/constant" 其中文件名不带properties后缀
* @return
*/
public static ResourceBundle getResource(String proPath) {
return ResourceBundle.getBundle(proPath);
}
public static void main(String[] args) {
ResourceBundle resource = getResource("conf/cnfParams");
Set<String> strings = resource.keySet();
for (String string : strings) {
String string1 = resource.getString(string);
System.out.println(string1);
}
}
}