public static String doUpload(MultipartFile mfile, String filePath){ if (!mfile.isEmpty()) { //文件绝对路径 String path = Constants.file_home+ filePath; //文件后缀 String suffix = StringUtils.substringAfterLast(mfile.getOriginalFilename(), ".").toLowerCase(); File file = new File(path); if (!file.exists() || !file.isDirectory()) { file.mkdirs(); } //fileNameGenerator是文件名的生成策略,可自行设计 path += "/"+fileNameGenerator(suffix); File outfile = new File(path); try { FileUtils.copyInputStreamToFile(mfile.getInputStream(), outfile); } catch (IOException e) { e.printStackTrace(); } return path; } return ""; } |
|
来自: 书屋随身带 > 《对文件的操作-上传/下载...》