springboot获取项目路径

File path =null;

      try {

path =new File(ResourceUtils.getURL("classpath:").getPath());

      }catch (FileNotFoundException e) {

// nothing to do

      }

if (path ==null || !path.exists()) {

path =new File("");

      }

String pathStr = path.getAbsolutePath();

// 如果是在eclipse中运行,则和target同级目录,如果是jar部署到服务器,则默认和jar包同级

      pathStr = pathStr.replace("\\target\\classes", "");

      //System.out.println(pathStr+"\\upload");

      return pathStr+"\\upload\\";

你可能感兴趣的:(springboot获取项目路径)