项目的资源目录路径如下:
package com.zzj.spring.boot.util;
import java.io.*;
import java.util.Properties;
public class PropertyUtil {
static Properties prop;
public static String getProperty(String key) throws Exception {
if(prop==null)
loadPropertyFile();
String value=prop.getProperty(key);
if(value==null||value.equalsIgnoreCase(""))
value="";
return value;
}
private static Properties loadPropertyFile() throws Exception {
//获取resources目录路径
String rootDir=PropertyUtil.class.getClassLoader().getResource("").getPath();
String filepath=rootDir+"bussiness.properties";
prop=new Properties();
InputStream in = new BufferedInputStream(new FileInputStream(filepath));
prop.load(in);
return prop;
}
public static void main(String[] arvs) throws Exception {
String value= getProperty("linux.charset");
System.out.println(value);
}
}