File转为转MultipartFile

如题:

//读取文件
FileInputStream in_file = new FileInputStream(new File(path));

//转MultipartFile
MultipartFile multi = new MockMultipartFile( real_name, in_file);

只需要以上二行就可以,以下是解释在哪个包

MockMultipartFile 类  implements 实现自 MultipartFile
MultipartFile 接口 extends 继承 InputStreamSource

包名:

package org.springframework.mock.web;
package org.springframework.web.multipart;
org.springframework.web.multipart
public interface InputStreamSource {
    //只有一个方法,获取 InputStream流
    InputStream getInputStream() throws IOException;
}

 

 

你可能感兴趣的:(报错,java,spring,web)