zoukankan      html  css  js  c++  java
  • spring MVC 的MultipartFile转File读取

    转自:http://www.cnblogs.com/hahaxiaoyu/p/5102900.html

    第一种方法:

         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();
      先转换为字节数组,没试过;
  • 相关阅读:
    悬线法练习
    Codechef MAY 15 Counting on a directed graph
    Codechef MAY 15 Chef and Balanced Strings
    兔子与兔子
    雪花雪花雪花
    约数之和
    分形之城
    递归实现组合型、指数型、排列型 枚举
    最短Hamilton路径
    六十四位整数乘法
  • 原文地址:https://www.cnblogs.com/XiDaPuBen/p/10523665.html
Copyright © 2011-2022 走看看