编程语言
首页 > 编程语言> > Java-File转MultipartFile

Java-File转MultipartFile

作者:互联网

Java-File转MultipartFile

1、依赖

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.2.7.RELEASE</version>
        </dependency>    

2、代码     

String filePaht = "";
File imageFile = new File(filePath); FileInputStream in = new FileInputStream(imageFile); MultipartFile file = new MockMultipartFile("file", imageFile.getName(), "text/plain", IOUtils.toByteArray(in));

 

标签:Java,File,imageFile,file,new,MultipartFile
来源: https://www.cnblogs.com/StefanieYang/p/13230053.html