if (file != null && file.getSize() > 0) {
File physicalPathFile = new File(solutionPath);
if (!physicalPathFile.exists()) {
physicalPathFile.mkdirs();
}
//获取原始文件扩展名
String ext = FilenameUtils.getExtension(file.getOriginalFilename()).toLowerCase();
//上传文件保存到upload目录中 File.separator文件分隔符,为了跨平台
String newFileName = UUID.randomUUID().toString() + “.” + ext;
File cover = new File(solutionPath + File.separator + newFileName);
try {
file.transferTo(cover);//文件写入到目标地址
String filePath = “data/solution/” + newFileName;
return filePath;
} catch (IOException e) {
e.printStackTrace();
}
}
文件上传
最新推荐文章于 2022-12-21 18:17:32 发布