Multipartfile与File类型相互转换

1、M转F

File file = new File(path); 

FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), file);  

2、F转M

File file = new File("src/test/resources/input.txt");

FileInputStream input = new FileInputStream(file);

MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input));

你可能感兴趣的:(IO)