读书人

Java怎么读取properties文件

发布时间: 2012-12-19 14:13:14 作者: rapoo

Java如何读取properties文件

import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.Properties;import java.util.Enumeration;public final class Test{    private static Properties props = new Properties();    static public void main(String args[]) throws Exception{        try{            FileInputStream inStream = new FileInputStream(new File("dd"));            try{props.load(inStream);}finally{inStream.close();}        Enumeration enumKeys = props.keys();        String key, value = null;             while (enumKeys.hasMoreElements()){                    key = (String) enumKeys.nextElement();                    value = props.getProperty(key, "").trim();                    System.setProperty(key, value);                    }            }catch (RuntimeException e){                e.printStackTrace();            }    }}

读书人网 >编程

热点推荐