// String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
//获取文件的输入流
InputStream stream = file.getInputStream();
byte[] bytes = new byte[stream.available()];
stream.read(bytes);
//判断文件上传路径是否为null
if (StrUtil.isEmpty(fileUploadExcelPath)) {
System.out.println("======文件上传路径:" + fileUploadExcelPath);
throw new RRException(“文件上传路径配置错误”, 500);
}
//文件路径是当前时间加文件名,DateUtil为hutool的时间工具
String path=DateUtil.format(new Date(),“yyyyMMddHHmmss”)+file.getOriginalFilename();
//硬盘路径
String filePathDir = fileUploadExcelPath +path;
File newFile = new File(filePathDir);
File parent = newFile.getParentFile();
//判断路径是否存在
if (!parent.exists())
//创建文件
parent.mkdirs();
if (!newFile.exists())
file.transferTo(newFile);
ExcelLogEntity entity=new ExcelLogEntity();
SysUserEntity user = ShiroUtils.getUserEntity();
entity.setInsertDate(DateUtil.format(new Date(),“yyyy-MM-dd HH:mm:ss”));
entity.setPackageNumber(packageNumber);
entity.setSampleSize(sampleSize);
entity.setExcelname(path);
entity.setPath(filePathDir);
entity.setInsertBy(user.getUsername());
bizTestTaskService.save(entity);
System.out.println("======文件上传成功:" + filePathDir);
return R.ok();
将用户上传的excel文件保存到本地硬盘
最新推荐文章于 2021-09-10 14:30:56 发布