加载properties文件

来源:互联网 发布:网络监控结构图 编辑:程序博客网 时间:2024/05/22 01:34
package test;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import org.apache.commons.logging.LogFactory;public class JunitTest {    org.apache.commons.logging.Log log = LogFactory.getLog(JunitTest.class);    public void testLoadFile(){        FileInputStream fileInputStream = null;        try {            fileInputStream = new FileInputStream("C:\\config.properties");            java.util.Properties properties = new java.util.Properties();            properties.load(fileInputStream);            Object value = properties.get("a");            System.out.println(value.toString());        } catch (FileNotFoundException e) {            try {                fileInputStream.close();            } catch (IOException e1) {                log.error("JunitTest IOException "+e1);            }        } catch (IOException e) {            try {                fileInputStream.close();            } catch (IOException e1) {                log.error("JunitTest IOException "+e1);            }        }    }}
0 0
原创粉丝点击