本文實(shí)例講述了java簡(jiǎn)單讀取properties配置文件的方法。分享給大家供大家參考,具體如下:
讀取配置文件,小結(jié)如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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" )); } } |
希望本文所述對(duì)大家java程序設(shè)計(jì)有所幫助。
原文鏈接:http://blog.csdn.net/u011625492/article/details/72843639