Java读取配置Properties文件


config.properties:

  1. author=xmq    
  2. user=xmq  
  3. copyright=2012-2015  

java文件:

  1. import java.io.FileInputStream;  
  2. import java.util.Enumeration;  
  3. import java.util.Properties;  
  4.    
  5. class PropTest {  
  6.     public static void main(String[] args) {  
  7. Properties pps=new Properties();   
  8.     try {  
  9.         pps.load(new FileInputStream("config.properties"));  
  10.         Enumeration enum = pps.propertyNames();  
  11.         while (enum.hasMoreElements()) {  
  12.        String strKey = (String) enum1.nextElement();  
  13.        String strValue = pps.getProperty(strKey);  
  14.        System.out.println(strKey + "=" + strValue);  
  15.         }  
  16.     } catch (Exception e) {  
  17.         e.printStackTrace();  
  18.     }  
  19.     }  
  20. }  

 

相关内容