实现代码如下
import java.util.Properties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
public class PropertiesLoader {
public static Properties getPro(String pathLocation){
Properties pro = null;
try{
EncodedResource encodedResource = new EncodedResource(new ClassPathResource(pathLocation), "utf-8");
pro = PropertiesLoaderUtils.loadProperties(encodedResource);
}catch (Exception e) {
}
if(pro == null){
pro = new Properties();
}
return pro;
}
public static void main(String[] args) {
Properties pro = PropertiesLoader.getPro("file:./config/custom.properties");
}
}