- 代码实现
package qf22020310_properties;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesUtils {
private static PropertiesUtils pu;
Properties p;
private PropertiesUtils() {
try {
p = new Properties();
InputStream ras = PropertiesUtils.class.getResourceAsStream("properties.properties");
p.load(ras);
} catch (IOException e) {
e.printStackTrace();
}
}
public static synchronized PropertiesUtils getInstance() {
if (pu == null) {
synchronized (PropertiesUtils.class){
if(pu==null){
pu = new PropertiesUtils();
}
}
}
return pu;
}
public String getValue(String name) {
return p.getProperty(name);
}
}