Java如何优雅的进行文件上传
transferTo方法
上代码:
public void uploadFile(MultipartFile file,String isSrc) {
File file1=new File("C:/Users/DD/Desktop/file/"+file.getOriginalFilename());
System.out.println(file.getName());
log.info(file.getName());
String filePath="C:/Users/DD/Desktop";
if (!file1.exists()) {
if (!file1.mkdirs()) {
log.error("创建文件夹异常");
}
}
try{
file.transferTo(file1);
}catch (Exception e){
e.printStackTrace();
}
}