java上传文件
public void upload(MultipartFile file, String saveurl,String showurl,) throws Exception { try { String suffix = file.getOriginalFilename().substring( //文件后缀 file.getOriginalFilename().lastIndexOf(".") + 1); File destFile = new File(saveurl); if (!destFile.exists()) { destFile.mkdirs(); } String fileNameNew = getFileNameNew() + "." + suffix;//新的文件名 File f = new File(destFile.getAbsoluteFile() + "/" + fileNameNew);//保存路径
f.createNewFile();
file.transferTo(f); // fileName = basePath + destDir + fileNameNew;
fileName = saveurl + fileNameNew;
oldfileName = file.getOriginalFilename();
newfileName = fileNameNew;
}
catch (Exception e) { throw e; }
}