Java语言*初级版

Java语言*初级版:
探讨Java语言基础知识,基本语法等。

-------------------------------------------------------------------
一、java读取properties文件源代码:
读取文件的类文件:

package com.config;

import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;

public class DAOConfig {

private static Logger log = Logger.getLogger(DAOConfig.class);

private static Properties pros = null;

private synchronized static void loadInitFile() {
if (pros == null) {
pros = new Properties();
}
try {
InputStream inStream = DAOConfig.class
.getResourceAsStream("/daoConfig.properties");
pros.load(inStream);
log.info("Initialize DAOConfig success!");
} catch (Exception e) {
log.error("Loading daoConfig.properties fail!!");
log.error(e);
e.printStackTrace();
}
}

public static String getProperty(String propName) {
loadInitFile();
return pros.getProperty(propName);
}

public static void main(String[] args) {
System.out.println(DAOConfig.getProperty("ImplDAOFactory.className"));

}
}



 

你可能感兴趣的:(java,apache,log4j)