package com.dress.common.util;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Properties;
public class PropertiesUtil {
private static Hashtable hash = new Hashtable();
private final static String FILENAME = "upload.properties";
private PropertiesUtil() {
}
/**
* 得到文件内容
*
* @param fileName
* @return
*/
public static Properties getProperties(String fileName) {
InputStream input = null;
Properties prop = null;
try {
prop = (Properties) hash.get(fileName);
if (prop == null) {
try {
input = new FileInputStream(fileName);// 全路径
} catch (Exception ex) {
if (fileName.startsWith("/")) {
input = PropertiesUtil.class
.getResourceAsStream(fileName);// 只有/+文件名字
} else {
input = PropertiesUtil.class.getResourceAsStream("/"
+ fileName);// 只有文件名字的
}
}
prop = new Properties();
prop.load(input);
if (input != null) {
input.close();
}
}
} catch (Exception e) {
// logger.error(e);
return null;
}
return prop;
}
/**
*通过key 和文件名称得到文件内容
*
* @param fileName
* @return
*/
public static String getProperties(String fileName,String key) {
Properties prop = null;
try {
prop=getProperties(fileName);
return prop.getProperty(key);
} catch (Exception e) {
// logger.error(e);
return "";
}
}
/**
* 通过key得到值
*
* @param key
* @return
*/
public static String getProperty(String key) {
try {
Properties prop = PropertiesUtil.getProperties(FILENAME);
if (null == prop)
return null;
return prop.getProperty(key);
} catch (Exception ex) {
return null;
}
}
/**
* 通过key得到拥有默认的值
*
* @param key
* @return
*/
public static String getProperty(String key, String defaultValue) {
try {
Properties prop = PropertiesUtil.getProperties(FILENAME);
if (null == prop)
return null;
return prop.getProperty(key, defaultValue);
} catch (Exception ex) {
return null;
}
}
/**
* 通过key得到数组值
*
* @param key
* @return
*/
public static String getProperty(String key, String[] array) {
try {
Properties prop = PropertiesUtil.getProperties(FILENAME);
if (null == prop)
return null;
String str = prop.getProperty(key);
for (int i = 0; i < array.length; i++) {
str = str.replaceAll("\\{" + (i + 1) + "\\}", array[i]);
}
return str;
} catch (Exception ex) {
return null;
}
}
}
Dom4j_demo.rar_DEMO_dom4j de_dom4j demo_dom4j demo project_xml读
版权申诉
5 浏览量
2022-09-14
17:11:35
上传
评论
收藏 244KB RAR 举报
御道御小黑
- 粉丝: 58
- 资源: 1万+
最新资源
- 学生成绩管理系统-C++版本
- 吉林大学离散数学2笔记.pdf
- 通道处理过程的模拟通常涉及对通道处理机制的理解与实现.txt
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈