multipartfile创建文件流_MultipartFile 转 File
时间: 2023-10-12 19:15:09 浏览: 181
multipartfile转file.md
可以通过以下步骤将 MultipartFile 转换为 File:
1. 获取 MultipartFile 的字节数组:
```java
byte[] bytes = multipartFile.getBytes();
```
2. 创建临时文件:
```java
File tempFile = File.createTempFile("prefix", "suffix");
```
3. 将字节数组写入临时文件:
```java
FileOutputStream outputStream = new FileOutputStream(tempFile);
outputStream.write(bytes);
outputStream.close();
```
完整代码如下:
```java
MultipartFile multipartFile = ...;
byte[] bytes = multipartFile.getBytes();
File tempFile = File.createTempFile("prefix", "suffix");
FileOutputStream outputStream = new FileOutputStream(tempFile);
outputStream.write(bytes);
outputStream.close();
```
阅读全文