读取Propertis
public class PropertiesHandler {
private static Logger logger = LoggerFactory.getLogger(PropertiesHandler.class);
public static void main(String[] args) throws Exception {
method01();
}
public static void method01() throws Exception {
Properties properties = new Properties();
InputStream inputStream = PropertiesHandler.class.getResourceAsStream("/test.properties");
properties.load(inputStream);
Enumeration<String> en = (Enumeration<String>) properties.propertyNames();
getPropertisData(properties);
}
public static void method02() throws Exception {
Properties properties = new Properties();
InputStream inputStream = PropertiesHandler.class.getResourceAsStream("/test.properties");
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,"utf-8"));
properties.load(br);
getPropertisData(properties);
}
public static void method03() throws Exception {
Properties properties = PropertiesLoaderUtils.loadAllProperties("test.properties");
Enumeration<String> en = (Enumeration<String>) properties.propertyNames();
while(en.hasMoreElements()) {
String key = en.nextElement();
String value = (String) properties.get(key);
value = new String(value.getBytes("ISO-8859-1"),"UTF-8");
logger.info(key+" : "+value);
}
}
public static void method04() throws Exception {
ResourceBundle bundle = ResourceBundle.getBundle("test");
Enumeration<String> en = bundle.getKeys();
while(en.hasMoreElements()) {
String key = en.nextElement();
String value = bundle.getString(key);
value = new String(value.getBytes("ISO-8859-1"),"UTF-8");
logger.info(key+" : "+value);
}
}
public static void getPropertisData(Properties properties) throws UnsupportedEncodingException{
Enumeration<String> en = (Enumeration<String>) properties.propertyNames();
while(en.hasMoreElements()) {
String key = en.nextElement();
String value = (String) properties.get(key);
logger.info(key+" : "+value);
}
}
}```
public class PropertiesHandler {
private static Logger logger = LoggerFactory.getLogger(PropertiesHandler.class);
public static void main(String[] args) throws Exception {
method01();
}
public static void method01() throws Exception {
Properties properties = new Properties();
InputStream inputStream = PropertiesHandler.class.getResourceAsStream("/test.properties");
properties.load(inputStream);
Enumeration<String> en = (Enumeration<String>) properties.propertyNames();
getPropertisData(properties);
}
public static void method02() throws Exception {
Properties properties = new Properties();
InputStream inputStream = PropertiesHandler.class.getResourceAsStream("/test.properties");
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,"utf-8"));
properties.load(br);
getPropertisData(properties);
}
public static void method03() throws Exception {
Properties properties = PropertiesLoaderUtils.loadAllProperties("test.properties");
Enumeration<String> en = (Enumeration<String>) properties.propertyNames();
while(en.hasMoreElements()) {
String key = en.nextElement();
String value = (String) properties.get(key);
value = new String(value.getBytes("ISO-8859-1"),"UTF-8");
logger.info(key+" : "+value);
}
}
public static void method04() throws Exception {
ResourceBundle bundle = ResourceBundle.getBundle("test");
Enumeration<String> en = bundle.getKeys();
while(en.hasMoreElements()) {
String key = en.nextElement();
String value = bundle.getString(key);
value = new String(value.getBytes("ISO-8859-1"),"UTF-8");
logger.info(key+" : "+value);
}
}
public static void getPropertisData(Properties properties) throws UnsupportedEncodingException{
Enumeration<String> en = (Enumeration<String>) properties.propertyNames();
while(en.hasMoreElements()) {
String key = en.nextElement();
String value = (String) properties.get(key);
logger.info(key+" : "+value);
}
}
}