读取properties的内容

来源:互联网 发布:先锋功放app软件 编辑:程序博客网 时间:2024/05/18 01:35
public static void main(String[] args) {
Properties props = new Properties();
        try {
            InputStream in = new BufferedInputStream(new FileInputStream(Utils.getTruePath()+
            "/WEB-INF/classes/com/jerrys/jerseyrest/properties/systemconfig.properties"));            
            props.load(in);
            Enumeration<?> en = props.propertyNames();
            while (en.hasMoreElements()) {
                String key = (String) en.nextElement();
                String Property = props.getProperty(key);
                System.out.println(key + "=" + Property);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

}


=============================================================

package com.jerrys.jerseyrest.utils;


import java.io.File;


public class Utils {


public static String notNull(String param) {
return param == null ? "" : param.trim();
}


public static String getTruePath() {
File f = new File(Utils.class.getResource("/").getPath());
String path = f.getPath();
path = notNull(path);
int index = path.indexOf("WEB-INF");
if (index > 0) {
return path.substring(0, index).replace("\\", "/");
} else {
return path.replace("\\", "/");
}
}




}

0 0