PropertyUtil

来源:互联网 发布:mac pro怎么安装双系统 编辑:程序博客网 时间:2024/05/15 14:07
import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.Properties;/** * @author dchen * @date 2013-6-21 上午09:26:17 */public class PropertyUtil {public static String getValueByProperty(String key)  {    Properties p = new Properties();    try {      InputStream in = PropertyUtil.class.getResourceAsStream("/config/chat_config.properties");      p.load(in);    } catch (FileNotFoundException e) {      e.printStackTrace();    } catch (IOException e) {      e.printStackTrace();    }    String path = p.getProperty(key);    return path;  }  public static String getValueByProperty(String key, String filePath)  {    Properties p = new Properties();    String defaultPath = "/config/chat_config.properties";    if (filePath == null)      filePath = defaultPath;    try    {      InputStream in = PropertyUtil.class.getResourceAsStream(filePath);      p.load(in);    } catch (FileNotFoundException e) {      e.printStackTrace();    } catch (IOException e) {      e.printStackTrace();    }    String path = p.getProperty(key);    return path;  }}

0 0