公用文件上传

    <!-- File Upload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.3</version>
    </dependency>


我正在尝试将文件转换为MultipartFile

 Line#1 ) File file = new File("C:\\Users\\Foo\\AppData\\Local\\Temp\\ErrorFile-1538475847143.csv");
 Line#2 ) FileItem fileItem = new DiskFileItem("file", "text/csv", false, file.getName(), (int) file.length(), file.getParentFile());
 Line#3 ) MultipartFile multipartFile = new CommonsMultipartFile(fileItem);


但是Line#2抛出异常

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.apache.commons.fileupload.disk.DiskFileItem.toString()


有什么决议吗?

最佳答案

这解决了我的问题:

fileItem.getOutputStream();

10-06 14:22