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();
    }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章