java获得配置文件数据
2009-11-06 20:56:23 来源:WEB开发网核心提示:以下是需要获得配置文件的类,其中获得/config.PRoperties 文件的数据view plaincopy to clipboardprint?package com.chinacache.boss.queryservice.util; import java.io.IOException; import jav
以下是需要获得配置文件的类,其中获得 /config.PRoperties 文件的数据
view plaincopy to clipboardprint?
package com.chinacache.boss.queryservice.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
public final class ConfigConstant {
static Logger logger = Logger
.getLogger(ConfigConstant.class);
public static Properties p = new Properties();
public static void init() {
InputStream in = null;
try {
in = ConfigConstant.class
.getResourceAsStream("/config.properties");
if (in != null)
p.load(in);
} catch (IOException e) {
e.printStackTrace();
logger.error("load " + "/config.properties" + " into Contants error");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
public static String getProperty(String key, String defaultValue) {
return p.getProperty(key, defaultValue);
}
public static String getProperty(String key) {
return p.getProperty(key);
}
public static Object setProperty(String key, String Value) {
return p.setProperty(key, Value);
}
}
package com.chinacache.boss.queryservice.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
public final class ConfigConstant {
static Logger logger = Logger
.getLogger(ConfigConstant.class);
public static Properties p = new Properties();
public static void init() {
InputStream in = null;
try {
in = ConfigConstant.class
.getResourceAsStream("/config.properties");
if (in != null)
p.load(in);
} catch (IOException e) {
e.printStackTrace();
logger.error("load " + "/config.properties" + " into Contants error");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
public static String getProperty(String key, String defaultValue) {
return p.getProperty(key, defaultValue);
}
public static String getProperty(String key) {
return p.getProperty(key);
}
public static Object setProperty(String key, String Value) {
return p.setProperty(key, Value);
}
}
此句是用来调用/config.properties 里的selectdays属性值:
String shouldLastDaysStr=ConfigConstant.getProperty("selectdays");
/config.properties 文件内容:
selectdays=33
basicbak=200808
view plaincopy to clipboardprint?
package com.chinacache.boss.queryservice.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
public final class ConfigConstant {
static Logger logger = Logger
.getLogger(ConfigConstant.class);
public static Properties p = new Properties();
public static void init() {
InputStream in = null;
try {
in = ConfigConstant.class
.getResourceAsStream("/config.properties");
if (in != null)
p.load(in);
} catch (IOException e) {
e.printStackTrace();
logger.error("load " + "/config.properties" + " into Contants error");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
public static String getProperty(String key, String defaultValue) {
return p.getProperty(key, defaultValue);
}
public static String getProperty(String key) {
return p.getProperty(key);
}
public static Object setProperty(String key, String Value) {
return p.setProperty(key, Value);
}
}
package com.chinacache.boss.queryservice.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
public final class ConfigConstant {
static Logger logger = Logger
.getLogger(ConfigConstant.class);
public static Properties p = new Properties();
public static void init() {
InputStream in = null;
try {
in = ConfigConstant.class
.getResourceAsStream("/config.properties");
if (in != null)
p.load(in);
} catch (IOException e) {
e.printStackTrace();
logger.error("load " + "/config.properties" + " into Contants error");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
public static String getProperty(String key, String defaultValue) {
return p.getProperty(key, defaultValue);
}
public static String getProperty(String key) {
return p.getProperty(key);
}
public static Object setProperty(String key, String Value) {
return p.setProperty(key, Value);
}
}
此句是用来调用/config.properties 里的selectdays属性值:
String shouldLastDaysStr=ConfigConstant.getProperty("selectdays");
/config.properties 文件内容:
selectdays=33
basicbak=200808
[]
- ››JavaScript拖拽原理的实现
- ››javascript事件列表解说
- ››Javascript代码优化工具UglifyJS
- ››Java Bean属性值动态设置
- ››JavaScript Confirm 失效的解决办法
- ››JavaScript页面内拖拽原理分析
- ››获得Android Linux系统增删文件的权限
- ››javascript中select的常用操作
- ››javascript+css无刷新实现页面样式的更换
- ››Java Web Services:不使用客户端证书的WS-Securit...
- ››Java开发2.0: 使用Amazon SimpleDB实现云存储,第...
- ››Java异常处理及其应用
更多精彩
赞助商链接