public class PropertyUtil {
/**
* 得到Properties
*
* @param path
* @return
*/
public static Properties getProperties(String path) {
if (path == null || path.equals(""))
return null;
Properties prop = new Properties();
InputStream in;
try {
in = PropertyUtil.class.getClassLoader().getResourceAsStream(path);
prop.load(in);
} catch (Exception e1) {
e1.printStackTrace();
}
return prop;
}
/**
* 得到给出键的属性值
*
* @param path
* @param key
* @return
*/
public static String getProperty(String path, String key) {
if (path == null || path.equals("") || key == null || key.equals(""))
return null;
Properties prop = new Properties();
InputStream resource = System.class.getResourceAsStream(path);
try {
prop.load(resource);
} catch (IOException e) {
e.printStackTrace();
}
return prop.getProperty(key);
}
/**
* 得到给定键的属性值
*
* @param resource
* @param key
* @return
*/
public static String getProperty(InputStream resource, String key) {
if (resource == null || key == null || key.equals(""))
return null;
Properties prop = new Properties();
try {
prop.load(resource);
} catch (IOException e) {
e.printStackTrace();
}
return prop.getProperty(key);
}
}
/**
* 得到Properties
*
* @param path
* @return
*/
public static Properties getProperties(String path) {
if (path == null || path.equals(""))
return null;
Properties prop = new Properties();
InputStream in;
try {
in = PropertyUtil.class.getClassLoader().getResourceAsStream(path);
prop.load(in);
} catch (Exception e1) {
e1.printStackTrace();
}
return prop;
}
/**
* 得到给出键的属性值
*
* @param path
* @param key
* @return
*/
public static String getProperty(String path, String key) {
if (path == null || path.equals("") || key == null || key.equals(""))
return null;
Properties prop = new Properties();
InputStream resource = System.class.getResourceAsStream(path);
try {
prop.load(resource);
} catch (IOException e) {
e.printStackTrace();
}
return prop.getProperty(key);
}
/**
* 得到给定键的属性值
*
* @param resource
* @param key
* @return
*/
public static String getProperty(InputStream resource, String key) {
if (resource == null || key == null || key.equals(""))
return null;
Properties prop = new Properties();
try {
prop.load(resource);
} catch (IOException e) {
e.printStackTrace();
}
return prop.getProperty(key);
}
}