import java.io.InputStream;
import java.util.Properties;
public class PropertiesHelper {
private static final String CONFIG_FILE = "user.properties";
public static void main(String[] args) throws Exception {
Properties prop = load();
System.out.println(prop.get("strUserId"));
}
private static Properties load(){
InputStream in = null;
Properties properties = null;
try {
properties = new Properties();
in = PropertiesHelper.class.getClassLoader().getResourceAsStream(CONFIG_FILE);
properties.load(in);
Properties localProperties1 = properties;
return localProperties1;
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (in != null){
try {
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return properties;
}
public static String getProperties(String key){
Properties prop = load();//每次都重新加载
if(prop != null){
System.out.println("key:"+key);
return (String)prop.get(key);
}
return null;
}
}
import java.util.Properties;
public class PropertiesHelper {
private static final String CONFIG_FILE = "user.properties";
public static void main(String[] args) throws Exception {
Properties prop = load();
System.out.println(prop.get("strUserId"));
}
private static Properties load(){
InputStream in = null;
Properties properties = null;
try {
properties = new Properties();
in = PropertiesHelper.class.getClassLoader().getResourceAsStream(CONFIG_FILE);
properties.load(in);
Properties localProperties1 = properties;
return localProperties1;
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (in != null){
try {
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return properties;
}
public static String getProperties(String key){
Properties prop = load();//每次都重新加载
if(prop != null){
System.out.println("key:"+key);
return (String)prop.get(key);
}
return null;
}
}