package com.javaeye.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
public class ConfigUtil {
private static Properties props = null;
private static File configFile = null;
private static long fileLastModified = 0L;
private static void init() {
URL url = ConfigUtil.class.getClassLoader().getResource("global.properties");
configFile = new File(url.getFile());
fileLastModified = configFile.lastModified();
props = new Properties();
load();
}
private static void load() {
try {
props.load(new FileInputStream(configFile));
fileLastModified = configFile.lastModified();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static String getConfig(String key) {
if ((configFile == null) || (props == null)) init();
if (configFile.lastModified() > fileLastModified) load();
return props.getProperty(key);
}
}
分享到:
相关推荐
1. android中对properties的简单的封装,.properties文件放置assetes文件下面。 2. 具体见 http://blog.csdn.net/wuyuxing24/article/details/50895209
log4j.properties 的使用详解(含log4j.properties)
主要介绍了Spring Boot中配置文件application.properties使用及spring boot读取application.properties文件的方式,需要的朋友参考下吧
本文侧重于了解自定义properties文件,以及properties中的数据格式,在gradle中如何使用等知识点。 一、概述 在Android Studio 创建一个项目的时候,rootProject下面会生成gradle.properties和local.properties文件...
使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name)); Properties p = new Properties(); p.load(in); 2。使用java.util....
赠送jar包:eigenbase-properties-1.1.5.jar; 赠送原API文档:eigenbase-properties-1.1.5-javadoc.jar; 赠送源代码:eigenbase-properties-1.1.5-sources.jar; 赠送Maven依赖信息文件:eigenbase-properties-...
主要介绍了Python实现读取Properties配置文件的方法,结合实例形式分析了Python读取Properties配置文件类的定义与使用相关操作技巧,需要的朋友可以参考下
好用的properties插件,好用的properties插件,好用的properties插件,呵呵~
javaproperties通过基于json模块的简单API提供对读写(简单的面向行格式和XML)的支持-尽管,为了恢复Java迷,它还包括旨在匹配行为的Properties类。 Python 尽可能多地使用 。 javaproperties版本的javaproperties...
myeclipse properties Editor 插件
myeclipse properties插件 2010之后可以使用 myeclipse properties插件 2010之后可以使用
eclipse查看properties插件
使用Java中的Properties类的方法,以及类加载器来读取配置文件中的信息。可以读取.properties文件和.cfg文件。详细代码+注释+测试例子
properties文件解析工具的制作过程及用法演示,使用者只需要提供properties文档的路径,即可使用解析工具里面的方法,根据键获得值。
properties的使用,与对文件的操作
每次要用jdk里面的native2ascii命令去转换编码方式是比较麻烦的,用PropertiesEditor去编辑就会自动进行编码转换,直接在properties文件中输入中文保存就行,方便了好多 在MyEclipse中要使用PropertiesEditor工具,...
主要介绍了详解spring boot 使用application.properties 进行外部配置,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
虽然可以native2ascii进行解决,但是使用起来不方便,为了解决这个问题,可以为Eclipse安装Properties Editor插件解决这个问题。 Properties Edito官网地址:http://propedit.sourceforge.jp/index_en.html ...
properties与json互相装换, 主要是为了将以前的properties配置存入XDiamond配置中心... 使用:PropToJson.toJSONString(resourseArr,true) resourseArr为资源文件地址数组 true为对应txt文件到本地; false为不输出到本地
利用Java的Properties 类读取配置文件信息! 读取Properties文件的例子