当前位置:网站首页>MytipartFile与File的相互转换
MytipartFile与File的相互转换
2022-06-28 10:51:00 【小玩偶啊】
1. MutipartFile 转换为File
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public File multipartFileToFile(MultipartFile file) throws Exception {
File toFile = null;
if (file.equals("") || file.getSize() <= 0) {
file = null;
} else {
InputStream ins = null;
ins = file.getInputStream();
toFile = new File(file.getOriginalFilename());
inputStreamToFile(ins, toFile);
ins.close();
}
return toFile;
}
2. File转换为MutipartFile
private static void inputStreamToFile(InputStream ins, File file) {
try {
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
ins.close();
} catch (Exception e) {
e.printStackTrace();
}
}边栏推荐
- How to use dataant to monitor Apache apisex
- Katalon framework tests web (XX) custom keywords and upload pop-up operations
- 树莓派无需显示屏的VNC Viewer方式的远程连接
- [practice] appium settings app is not running after 5000ms
- Teach you how to handle the reverse SVG mapping of JS
- 移动命令
- Knowing the details of redis RDB, you can step on many holes less
- 2022 Wu Enda machine learning specialization week 2 practice lab: linear expression
- Information hidden in the trend chart of Hong Kong London gold market
- Installing MySQL database (CentOS) in Linux source code
猜你喜欢

一文读懂 12种卷积方法(含1x1卷积、转置卷积和深度可分离卷积等)

idea连接sql sever失败

As shown in the figure, the SQL row is used to convert the original table of Figure 1. Figure 2 wants to convert it

Discard Tkinter! Simple configuration to quickly generate cool GUI!

Threads and thread pools

Summary of characteristics of five wireless transmission protocols of Internet of things

mysql数据库概述以及安装过程

爱可可AI前沿推介(6.28)
Ribbon核心源码解析

MySQL cannot be opened. Flash back
随机推荐
flink1.15,支持mysql视图吗?我这边在table-name处配置视图名保存,找不到表。想
Installing MySQL database (CentOS) in Linux source code
Fabric. How to use js brush?
sqlcmd 连接数据库报错
[NLP] this year's college entrance examination English AI score is 134. The research of Fudan Wuda alumni is interesting
【agora】get 一个 agora_refptr 对象的用法示例
As shown in the figure, the SQL row is used to convert the original table of Figure 1. Figure 2 wants to convert it
Mysql database overview and installation process
Mongo数据库
[Unity]EBUSY: resource busy or locked
【力扣——动态规划】整理题目1:基础题目:509、70、746、62、63、343、96(附链接、题目描述、解题方法及代码)
datetime与logging模块
Transactions proof in appliedzkp zkevm (10)
Metersphere implements UI automation elements that are not clickable (partially occluded)
How does ETF position affect spot gold price?
[Li Kou - dynamic planning] sort out topic 1: basic topics: 509, 70, 746, 62, 63, 343, 96 (with links, topic descriptions, problem solving methods and codes)
[function suggestion] select a space when multiple workspaces are started
Debug debugging in katalon
The boss asked me to write an app automation -- yaml file reading -- with the whole framework source code attached
The introduction of flink-sql-mysql-cdc-2.2.1 has solved many dependency conflicts?