package com.yanek.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
public final class Global {
public static void main(String[] args)
{
System.out.println(Global.exptype);
System.out.println(Global.descDic);
System.out.println(Global.sourceDic);
}
/** 日志记录 */
static Logger log = Logger.getLogger(Global.class.getName());
/** 应用程序配置参数缓存 */
private static Properties appPropertiesCache;
/** 服务配置文件名 */
//private static String config_file = "conf/mail.properties";
private static String config_file = "config.properties";
public static String APPLICATION_ROOT = null;
public static String exptype = null; //出库类型
public static String sourceDic = null; //来源目录
public static String descDic = null; //目标目录
static {
try {
APPLICATION_ROOT = System.getProperty("user.dir");
System.out.println("properties file:" + config_file);
appPropertiesCache = loadProperties(config_file);
sourceDic = appPropertiesCache.getProperty("sourceDic");
descDic=appPropertiesCache.getProperty("descDic");
exptype=appPropertiesCache.getProperty("exptype");
} catch (IOException e) {
e.printStackTrace();
}
}
/***********************************************************************************************
* 根据给定名字查找资源,返回其输入流
*
* @param uri
* 资源名
* @return 输入流
*/
public static InputStream getResourceAsStream(String uri) {
return Global.class.getClassLoader().getResourceAsStream(uri);
}
/***********************************************************************************************
* 载入属性文件
*
* @param 文件基于类路径的相对路径名
* @return 根据属性文件生成的Properties对象
* @throws IOException
*/
public static Properties loadProperties(String uri) throws IOException {
Properties result = null;
InputStream in = getResourceAsStream(uri);
if (in != null) {
try {
result = new Properties();
result.load(in);
} finally {
in.close();
//ResourceMgr.closeQuietly(in);
}
} else
throw new IOException("载入属性文件失败!" + uri);
return result;
}
/***********************************************************************************************
* 根据指定键值取应用程序配置属性
*
* @param key
* 该属性在配置文件中的键
* @return 该属性在配置文件中的字符串值
*/
public static String getAppProperty(String key) {
String value = Global.appPropertiesCache.getProperty(key);
if (value == null)
value = System.getProperty(key);
return value;
}
}
注意:配置文件在src根目录即可
config.properties
exptype=2
sourceDic=C://artistExp//in
descDic=C://artistExp//out
#descDic=////192.168.61.172//temp
#descDic=////192.168.61.172//temp
systype=new
分享到:
相关推荐
读取自定义属性文件内容,可以自己定义属性文件的名字,任何路径都可以
java读取属性文件通用方法,以及日志记录
NULL 博文链接:https://hylong05.iteye.com/blog/560603
连接数据库全部写在属性文件中,通过读取属性文件来连接。
vc读取文件属性资料vc读取文件属性资料
这是一个读取properties的类,用处挺大的 大家注意点就是这个properties是实现 map接口--继承Hashtable类!
* 得到属性文件的值 */ public String getValueByPropertyKey(String key) { String value = null; if (checkPropertyFile()) { value = getValue(key); } return value; } /* * get Value ...
java读取pdf文件作者、标题等属性
C语言对HDF文件数据集和属性的读写[文].pdf
因为他内部有一个ConfigParser 类来支持.ini 文件的读写,根据该类提供的方法程序员可以自由的来操作.ini 文件。而在Java 中,Java 支持的是.properties 文件的读写。JDK 内置的java.util.Properties 类为我们操作....
如何读取webroot文件下的属性文件
如何读取webroot文件下的属性文件
JAVA配置文件读取,加载操作
文件属性读写代码 vb C# 文件属性读写代码 vb C#
NULL 博文链接:https://xiaoxuejie.iteye.com/blog/1174273
c++文件读写.pdf
NULL 博文链接:https://wzwd111.iteye.com/blog/667867
JavaJNDI 数据链接池及 属性文件读取数据链接信息
读/写属性文件的工具类. PropertyUtil.java对Property文件读写进行了封装, 使开发人员对Property文件的读写更加容易。 在性能、实用性 方面还是可以的。