本文实例讲述了java简单读取properties配置文件的方法。分享给大家供大家参考,具体如下:
读取配置文件,小结如下
import java.io.FileNotFoundException;import java.io.IOException;import java.util.Properties;public class loadConf { private Properties prop = new Properties(); private void loadconf() throws FileNotFoundException, IOException { String path = "com/jlc/util/user.properties"; prop.load(loadConf.class.getClassLoader() .getResourceAsStream(path)); } public loadConf() throws FileNotFoundException, IOException { loadconf(); } public boolean chkProperty(String _key) { return prop.containsKey(_key); } public String getProperty(String _key) { return prop.getProperty(_key); } public static void main(String[] args) throws FileNotFoundException, IOException { loadConf mycnf = new loadConf(); System.out.println(mycnf.chkProperty("address")); System.out.println(mycnf.getProperty("poart")); }}
希望本文所述对大家java程序设计有所帮助。
新闻热点
疑难解答
图片精选