SpringBoot获取jar包路径

//linux和windows下通用
private String getJarFilePath() {
    ApplicationHome home = new ApplicationHome(getClass());
    File jarFile = home.getSource();
    return jarFile.getParentFile().toString();
}

 SpringBoot获取jar包路径_第1张图片

 

//	用户当前工作目录
System.getProperty("user.dir");
//判断目录是否存在
        File folder = new File(path);
        if (!folder.exists()) {
            folder.mkdirs();
        }

 返回上层路径jarFile.getParent()
根据系统获取分隔符File.separator

 

你可能感兴趣的:(SpringBoot,jar,java,spring)