首页>代码>基于SpringBoot框架开发的简单商城后台管理系统>/myshop/src/main/java/com/jacklin/myshop/common/FileUploadUtils.java
package com.jacklin.myshop.common; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; import java.util.UUID; /** * 文件上传工具类 */ public class FileUploadUtils { public static String uploadFile(MultipartFile file, String path) throws IOException { String name = file.getOriginalFilename(); //上传文件的真实名 String suffixName = name.substring(name.lastIndexOf("."));//截取拓展名 String uuid = UUID.randomUUID().toString(); String fileName = uuid + suffixName; //文件上传 File tempFile = new File(path, fileName); if (!tempFile.getParentFile().exists()) { tempFile.getParentFile().mkdir(); } if (tempFile.exists()) { tempFile.delete(); } tempFile.createNewFile(); file.transferTo(tempFile); return tempFile.getName(); } }
最近下载更多
最近浏览更多
刘守曜
3小时前
暂无贡献等级
1134116035
前天
暂无贡献等级
kwon6666
4月19日
暂无贡献等级
akittyboy LV9
4月16日
yhe107 LV3
4月16日
Luck_ZDM LV11
4月12日
zhanghao943 LV2
4月12日
RZX031513 LV1
4月10日
luo17017
3月25日
暂无贡献等级
qq549888060 LV8
3月24日