欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

spring MVC 的MultipartFile转File读取

发布时间:2023/12/2 39 豆豆
生活随笔 收集整理的这篇文章主要介绍了 spring MVC 的MultipartFile转File读取 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

第一种方法:

     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(); 先转换为字节数组,没试过; 注:参考链接:http://www.cnblogs.com/hahaxiaoyu/p/5102900.html

转载于:https://www.cnblogs.com/kings-9/p/7629159.html

总结

以上是生活随笔为你收集整理的spring MVC 的MultipartFile转File读取的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。