Properties文件的读取
来源:互联网 发布:瓜子二手车大数据应用 编辑:程序博客网 时间:2024/06/05 03:23
/**
*取得对应KEY的属性值
*@param 路径propFile String
*@param 关键字propNm String
*@return 关键字对应的属性值 String
*/
private static String propload(String propFile, String propNm){
String propValue = "";
//Properties:主要用于读取项目的配置文件(以.properties结尾的文件和xml文件)
Properties props = new Properties();
InputStream input = null;
URL url = null;
//ClassLoader:它就是用来加载Class文件到JVM(java虚拟机),以供程序使用的
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if(cl == null){
cl = ClassLoader.getSystemClassLoader();
url = cl.getResource(propFile);
try {
input = new FileInputStream(propFile.replaceAll("%20", "")); //window系统
props.load(input); //读取数据
//关键字对应的属性值
propValue = new String(props.getProperty(propNm).getBytes("ISO-8859-1"),"UTF-8");
input.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
if(input != null){
try {
input.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
return propValue;
}
*取得对应KEY的属性值
*@param 路径propFile String
*@param 关键字propNm String
*@return 关键字对应的属性值 String
*/
private static String propload(String propFile, String propNm){
String propValue = "";
//Properties:主要用于读取项目的配置文件(以.properties结尾的文件和xml文件)
Properties props = new Properties();
InputStream input = null;
URL url = null;
//ClassLoader:它就是用来加载Class文件到JVM(java虚拟机),以供程序使用的
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if(cl == null){
cl = ClassLoader.getSystemClassLoader();
url = cl.getResource(propFile);
try {
input = new FileInputStream(propFile.replaceAll("%20", "")); //window系统
props.load(input); //读取数据
//关键字对应的属性值
propValue = new String(props.getProperty(propNm).getBytes("ISO-8859-1"),"UTF-8");
input.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
if(input != null){
try {
input.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
return propValue;
}
- properties 文件的读取
- properties文件的读取
- Properties文件的读取
- Properties文件的读取。
- properties文件的读取
- properties文件的读取
- 读取properties文件的例子.
- 读取properties文件的方法
- properties文件的读取方式
- 读取Properties文件的方法
- 读取properties文件的方式
- 关于properties文件的读取
- properties文件的读取Util
- JAVA properties文件的读取
- Properties读取properties文件
- Properties 读取 Properties文件
- 【加载读取Properties】关于Properties文件的读取
- 获得properties文件的路径,读取properties文件的参数
- Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds
- java 取用sql2005结果集的问题
- 幸福不依赖于外界环境,而取决于我们的心态
- 输出1 到 5 的阶乘值
- 不容易系列
- Properties文件的读取
- axure教程(一)文本框焦点效果
- sigaction 函数解析
- tomcat下加载运行同一个复制项目错误 .
- 模运算
- 触摸屏三大技术介绍
- qt环境搭建预先需要的所有库
- 计算机视觉论文
- 多线程