- public class PropUtil
- {
- public static Properties getPropUtil () {
- Properties config = new Properties();
- InputStream is = null;
- try {
- is = PropUtil .class.getClassLoader().getResourceAsStream("prop.properties");
- config.load(is);
- } catch (IOException e) {
- } finally {//关闭资源
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
- }
- log.debug("return prop config");
- return config;
- }
- }
public class PropUtil
{
public static Properties getPropUtil () {
Properties config = new Properties();
InputStream is = null;
try {
is = PropUtil .class.getClassLoader().getResourceAsStream("prop.properties");
config.load(is);
} catch (IOException e) {
} finally {//关闭资源
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
log.debug("return prop config");
return config;
}
}
代码2:
- public class PropUtil {
- private static ResourceBundle resources;
- public static String getParam(String confFileName,String param) {
- resources = ResourceBundle.getBundle(confFileName);
- return resources.getString(param);
- }
- }
public class PropUtil {
private static ResourceBundle resources;
public static String getParam(String confFileName,String param) {
resources = ResourceBundle.getBundle(confFileName);
return resources.getString(param);
}
}
代码3:
- public static String getParameter(String key){
- Properties params = new Properties();
- FileInputStream in = null;
- String value =null;
- try
- {
- in = new FileInputStream("prop.properties");
- params.load(in);
- value = params.getProperty(key);
- }
- catch (java.io.IOException e)
- {
- e.printStackTrace();
- }finally {
- if(in!=null) {
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return value;
- }
public static String getParameter(String key){
Properties params = new Properties();
FileInputStream in = null;
String value =null;
try
{
in = new FileInputStream("prop.properties");
params.load(in);
value = params.getProperty(key);
}
catch (java.io.IOException e)
{
e.printStackTrace();
}finally {
if(in!=null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return value;
}