ConfUtil 读取配置文件工具类

来源:互联网 发布:网络机顶盒一般多少钱 编辑:程序博客网 时间:2024/06/05 06:12


利用 Java 本身自带的IO流 和 properties 工具类 读取配置文件


代码如下:

package test.io;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.util.Properties;public class ConfUtil {public static Properties p = null;/** * @param configFilePath * @param str * @return */public static String getConfig(String configFilePath, String str) {if(p == null){p = new Properties();}try {p.load(new BufferedInputStream(new FileInputStream(configFilePath)));return p.getProperty(str).trim();} catch (IOException e) {e.printStackTrace();}return null;}}

键值对型:如  name=zhangsan


对文件类型可以是 properties conf 等类型