第一种方法:

     MultipartFile file = xxx;
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem(); File f = fi.getStoreLocation();   会在项目的根目录的临时文件夹下生成一个文件; 第二种方法:    transferTo(File dest);   会在项目中生成一个新文件; 第三种方法:    File f = (File) xxx 强转即可。前提是要配置multipartResolver,要不然会报类型转换失败的异常。     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600"/>
<property name="maxInMemorySize" value="4096"/>
</bean>
  没试过;
第四种方法:
  Workbook wb = Workbook.getWorkbook(xxx .getInputStream());
  转换为输入流,直接读取;
第五种方法:
  byte[] buffer = myfile.getBytes();
  先转换为字节数组,没试过;
 //显示声明CommonsMultipartResolver为mutipartResolver
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver(){
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
resolver.setResolveLazily(true);//resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
resolver.setMaxInMemorySize(40960);
resolver.setMaxUploadSize(50*1024*1024);//上传文件大小 50M 50*1024*1024
return resolver;
}

springmvc 中将MultipartFile转为file,springboot 注入CommonsMultipartResolver的更多相关文章

  1. SpringMVC 上传文件 MultipartFile 转为 File

    在使用 SpringMVC 上传文件时,接收到的文件格式为 MultipartFile,但是在很多场景下使用都需要File格式的文件,记录下以便日后使用. 以下mFile为MultipartFile文 ...

  2. Springmvc 上传文件MultipartFile 转File

    转自:http://blog.csdn.net/boneix/article/details/51303207 业务场景:ssm框架 上传文件到应用服务器过程中要传到专有的文件服务器并返回url进行其 ...

  3. springmvc文件上传 参数为MultipartFile 转换为File

    package cn.com.mcd.controller;import java.io.File;import java.io.IOException;import java.io.Serializ ...

  4. SpringMVC 使用MultipartFile实现文件上传(转)

    http://blog.csdn.net/kouwoo/article/details/40507565 一.配置文件:SpringMVC 用的是 的MultipartFile来进行文件上传 所以我们 ...

  5. pandas中将timestamp转为datetime

    参考自:http://stackoverflow.com/questions/35312981/using-pandas-to-datetime-with-timestamps 在pandas Dat ...

  6. Opencv中将CvMat转为IplImage

    Opencv中将CvMat转为IplImage,并在内存获得起头指针,而不用cvSaveImage(),贴上代码 IplImage * imgg = NULL; imgg = cvCreateImag ...

  7. SpringMVC Web项目升级为Springboot项目(二)

    一.访问原项目地址,报404错误 由于原项目地址启动路径为http://localhost:8080/xxx Spring boot默认启动路径为http://localhost:8080/ 所以需要 ...

  8. [转]spring MultipartFile 转 File

    原文地址:https://www.jianshu.com/p/6cf99d39e170 File.createTempFile(String prefix, String suffix); 创建一个临 ...

  9. MultipartFile 转换为File

    选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 . MultipartFile multipartFile; File fil ...

随机推荐

  1. Android之手机振动和振铃

    一.振动的实现1.使用振动所需的权限 <uses-permission android:name="android.permission.VIBRATE" />2.相关 ...

  2. 好用的JS数字格式化

    /* *js格式化数字代码 * *value: 要格式化的数字值 *scale: 最多保留几位小数 *zeroed: 是否保留尾0 *percented: 是否转称百分比形式 * */ functio ...

  3. do{}while(0)

    有时会在源码中或在写代码时在宏定义中用到do...while(0). 采用这种方式进行宏定义, 主要是为了防止出现以下错误 : do{}while(0) 空的宏定义避免出现warnning. #def ...

  4. NSE入门--nmap 脚本基础

  5. LINQ简记(1):基本语法

    关于LINQ(语言集成查询)是.NET 3.5和Visual Studio 2008以上版本中引入的一种有趣的全新概念,语言版本有VB和C#,由于C#与.NET平台结合最为紧密,也是MS当初首推的语言 ...

  6. (蓝桥杯)第八届A组C/C++跳蚱蜢

    #include<iostream> #include<memory.h> #include<stack> #include<string> #incl ...

  7. PAT 1093. Count PAT's

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  8. 造成segment fault,产生core dump的可能原因

    1.内存访问越界 a) 由于使用错误的下标,导致数组访问越界 b) 搜索字符串时,依靠字符串结束符来判断字符串是否结束,但是字符串没有正常的使用结束符 c) 使用strcpy, strcat, spr ...

  9. [bzoj1941][Sdoi2010]Hide and Seek_KD-Tree

    Hide and Seek bzoj-1941 Sdoi-2010 题目大意:给出平面上n个点,选出一个点,使得距离这个点的最远点曼哈顿距离减去距离这个点的最近非己点的曼哈顿距离最小.输出最小曼哈顿距 ...

  10. [bzoj3037/2068]创世纪[Poi2004]SZP_树形dp_并查集_基环树

    创世纪 SZP bzoj-3037/2068 Poi-2004 题目大意:给你n个物品,每个物品可以且仅可以控制一个物品.问:选取一些物品,使得对于任意的一个被选取的物品来讲,都存在一个没有被选取的物 ...