/*
*
* File: AppProperties.java
* Date: 2005-6-28
* Author: fuwl
* project: DB2Trans
* Ver:1.00
* Note:
*/
package com.toone.egov.common.util;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
/**
* @author fuwl
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class AppProperties
{
private final static String PropFile = "App.properties" ;
private static AppProperties appProp = null;
private Properties prop;
/*私有默认构造函数,保证外界无法直接实例化*/
private AppProperties() throws IOException
{
prop = new Properties();
FileInputStream fis = new FileInputStream(PropFile);
prop.load(fis);
}
synchronized public static AppProperties getInstance() throws IOException
{
if(appProp == null)
{
appProp = new AppProperties();
}
return appProp;
}
public static void main(String args[]) throws Exception
{
System.out.println("prop 1.1");
System.out.println(AppProperties.getInstance().prop.getProperty("foo"));
}
}
此博客展示了Java中AppProperties类的代码实现。该类使用Properties加载配置文件,通过私有构造函数保证单例,提供getInstance方法获取实例,在main方法中可测试获取配置属性。涉及文件输入流、异常处理等操作。
1542

被折叠的 条评论
为什么被折叠?



