第一种方法:java
MultipartFile file = xxx;
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem(); web
File f = fi.getStoreLocation();spring
会在项目的根目录的临时文件夹下生成一个文件;数组
第二种方法:spa
transferTo(File dest);code
会在项目中生成一个新文件;ip
第三种方法: get
File f = (File) xxx 强转便可。前提是要配置multipartResolver,要否则会报类型转换失败的异常。string
<bean id=
"multipartResolver"
class
=
"org.springframework.web.multipart.commons.CommonsMultipartResolver"
>
<property name=
"maxUploadSize"
value=
"104857600"
/>
<property name=
"maxInMemorySize"
value=
"4096"
/>
</bean>