SpringBoot 文件上传至static路径相关问题

时间:2025-02-16 17:06:37

SpringBoot 文件上传至static路径相关问题
1、path 即为文件上传的存储位置
例如:
Tomcat 8.5\webapps\nn\WEB-INF\classes\static\img\upfile
2、参考代码

File path2 = new File(("classpath:static").getPath().replace("%20"," ").replace('/', '\\'));
  if(!()) path2 = new File("");
     //如果上传目录为/static/images/upload/,则可以如下获取:
     File upload2 = new File((),"img/upfile/");
     if(!()) ();
   String path=()+"/";
   (path, upload);