Java读取配置Properties文件
Java读取配置Properties文件
config.properties:
- author=xmq
- user=xmq
- copyright=2012-2015
java文件:
- import java.io.FileInputStream;
- import java.util.Enumeration;
- import java.util.Properties;
- class PropTest {
- public static void main(String[] args) {
- Properties pps=new Properties();
- try {
- pps.load(new FileInputStream("config.properties"));
- Enumeration enum = pps.propertyNames();
- while (enum.hasMoreElements()) {
- String strKey = (String) enum1.nextElement();
- String strValue = pps.getProperty(strKey);
- System.out.println(strKey + "=" + strValue);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
评论暂时关闭