import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class PropertiesUtil {
private static Properties properties = null;
private static final String PARAM_NAME = "param.properties";
//静态初始化解析
static{
if(properties == null){
try {
load();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void load() throws FileNotFoundException, IOException{
String path = PropertiesUtil.class.getResource("/").getPath();
properties = new Properties();
System.out.println(path + PARAM_NAME);
properties.load(new FileInputStream(path + PARAM_NAME));
}
public static String getValue(String key){
return properties.getProperty(key);
}
}
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class PropertiesUtil {
private static Properties properties = null;
private static final String PARAM_NAME = "param.properties";
//静态初始化解析
static{
if(properties == null){
try {
load();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void load() throws FileNotFoundException, IOException{
String path = PropertiesUtil.class.getResource("/").getPath();
properties = new Properties();
System.out.println(path + PARAM_NAME);
properties.load(new FileInputStream(path + PARAM_NAME));
}
public static String getValue(String key){
return properties.getProperty(key);
}
}