简单粗暴方法:
You can get the content of multipartFile by using the getBytes method and you can create an instance of the File class by using the FileOutputStream class.
public File convert(MultipartFile file)
{
File convFile = new File(file.getOriginalFilename());
convFile.createNewFile();
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes());
fos.close();
return convFile;
}
You can also use the transferTo method:
public File multipartToFile(MultipartFile multipart) throws IllegalStateException, IOException
{
File convFile = new File( multipart.getOriginalFilename());
multipart.transferTo(convFile);
return convFile;
}
原文:java - How to convert a multipart file to File? - Stack Overflow