美文网首页
读取配置文件的工具类

读取配置文件的工具类

作者: setsun | 来源:发表于2018-06-25 10:52 被阅读0次

static {

try {

URL url = PropertiesUtils.class.getProtectionDomain().getCodeSource().getLocation();

        System.out.println("url-->:" + url);

        String filePath = URLDecoder.decode(url.getPath(), "utf-8");

        System.out.println("filePath-->:"+ filePath);

        String path =null;

        if (filePath.contains("lib")){

path = filePath.substring(filePath.indexOf(":")+1,filePath.indexOf("/lib"));

        }else if (filePath.contains("target")){

path = filePath.substring(1,filePath.indexOf("/target"));

        }

System.out.println("path-->:" +path);

        properties.load(new FileReader(path+"/src/main/resources/utils.properties"));

    }catch (Exception e){

e.getLocalizedMessage();

    }

相关文章

网友评论

      本文标题:读取配置文件的工具类

      本文链接:https://www.haomeiwen.com/subject/sfneyftx.html