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();
}
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("\\", "/");
}
}
}