java web service 写入图片到web/img/

获取本类service路径,然后字符串截取和拼接
  String classpath= this.getClass().getResource("/").getPath();

            String path = classpath.substring(0,classpath.length() - "WEB-INF/classes/".length());

            System.out.println(path);

            Path file=new File(path+"assets/img/code.png").toPath();

原文地址:https://www.cnblogs.com/zhaocundang/p/10130832.html