java解析属性文件

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

public class ParsePropertyFile {

    public HashMap<String, String> getProperty(String propertyFile) {
        HashMap<String, String> hm = null;
        try {
            Properties props = new Properties();
            InputStream is = new FileInputStream(
                    new File(propertyFile).getAbsolutePath());
            props.load(is);
            Set<Object> keys = props.keySet();
            hm = new HashMap<String, String>();
            for (Iterator<Object> it = keys.iterator(); it.hasNext();) {
                String key = (String) it.next();
                hm.put(key, props.getProperty(key));                            
            }
            is.close();    
            
        } catch (IOException ie) {
            
        }
        return hm;
    }
}

 

posted on 2013-09-11 11:56  张飞_  阅读(1376)  评论(0编辑  收藏  举报

导航