Properties类使用

时间:2023-03-09 00:10:25
Properties类使用
package com.emolay.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties; public class PropertiesUtils { private static final Properties properties = new Properties(); static {
try {
load();
} catch (Exception e) {
}
}
private static void load(){
InputStream input = null;
try {
input = PropertiesUtils.class.getResourceAsStream("/application.properties");
properties.load(input);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public static String getProperty(String key){
String value = "";
if (properties.containsKey(key)) {
value = properties.getProperty(key);
}
return value;
} }