java读properties的通用类,兼容linux和windows
2016-05-19 20:02
477 查看
package util; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * 获取配置文件信息 * * @author Carl * */ public final class GetProperties { private static Properties prop = null; static{ prop = new Properties(); //设置properties文件路径,以src为根路径(config.properties 处于src根目录下) InputStream in = GetProperties.class.getResourceAsStream("/config.properties"); try { prop.load(in); } catch (IOException e) { System.out.println("读取配置文件失败---->>>>----(/src/config.properties)");//会失败!!!! e.printStackTrace(); } } /** * 根据传入的KEY获取配置文件中对应的值 * @param key * @return */ public static String getPropertieValue(String key){ String value = ""; value = prop.getProperty(key).trim(); return value; } } http://nannan408.iteye.com/blog/2022532
相关文章推荐
- CentOS7安装iptables防火墙
- Linux进程管理与调度-之-目录导航
- 每天一个Linux命令(21)find命令_xargs参数
- CentOS 6.5/6.6 安装mysql 5.7 最完整版教程
- Linux_Timer
- 让锐捷客户端在linux平台飞
- Linux例行性工作排程 (crontab)
- linux常用命令
- 在Linux中分别安装应用于不同平台的QT:PC;嵌入式X86;ARM。
- Linux下用crontab定时执行PHP程序有问题时候的解决方式
- Linux下的find命令
- Linux下对拍脚本与随机数生成器
- iostat查看io情况(监控Linux的8种方式)
- Linux 线程通信
- centos linux 服务器时间少8个小时的问题
- LINUX 挂载硬盘开机自启动
- Linux中常用的查找文件的命令
- linux安装软件(rpm/yum/apt-get/python)等解决依赖问题
- Linux下的多进程编程
- Linux系统调用--getrlimit()与setrlimit()函数详解