配置文件放置src根下
package socketTest;
import java.io.InputStream;
import java.util.Properties;
public class ConstantHelper {
public static void main(String[] args) {
String prop = ConstantHelper.getProp("imgPath");
System.out.println(prop);
}
private static Properties properties;
static {
try {
properties = new Properties();
// 使用ClassLoader加载properties配置文件生成对应的输入流
InputStream in = CClientTest.class.getClassLoader().getResourceAsStream("config.properties");
// 使用properties对象加载输入流
properties.load(in);
//获取key对应的value值
String imgPath = properties.getProperty("imgPath");
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getProp(String key) {
if (properties == null) {
return null;
}
return properties.getProperty(key);
}
}
config.properties
#nginx服务器地址
nginx.server=http://127.0.0.1:8099
#图片地址
imgPath=D:/VideoRec