当前位置:网站首页>工具类:base64格式的数据与本地文件的相互转换
工具类:base64格式的数据与本地文件的相互转换
2022-08-09 02:21:00 【abs(ln(1+NaN))】
public class UploadUtil {
//这里的pathName 必须具体到某一张图片或者某一个文件的名字,如 D:\\xxx\\xxx.jpg
public static void storeImageAtLocal(String base64ImgData,String pathName){
Base64.Decoder decoder = Base64.getDecoder();
byte[] bytes = decoder.decode(base64ImgData);
/*
* 字节流转文件
*/
FileOutputStream fos = null;
try {
fos = new FileOutputStream(pathName);
fos.write(bytes);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
//本地图片转base64编码数据
public static String getImageBase64Data(String localPath){
File file = new File(localPath); //URL url = new URL(src);
byte[] data = null;
try {
InputStream in = new FileInputStream(file); //InputStream in = url.openStream();
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
Base64.Encoder encoder = Base64.getEncoder();
return encoder.encodeToString(data);
}
}边栏推荐
- D. Tournament Countdown
- 考研人总结的时间管理7大忌,你中了几条?
- MySQL/Oracle字符串分割
- JDBC technology (1) - a simple JDBC test
- HCIP-R&S By Wakin自用笔记(2)OSPF之OSPF回顾、虚连接
- 力扣刷题记录4.1-----209. 长度最小的子数组
- Composer usage record
- 方法参数
- Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
- How to play knowledge graph in recommender system
猜你喜欢

Likou Brush Question Record 5.1-----59. Spiral Matrix II

Data recovery software EasyRecovery supports recovery of all types of files

终于有人把灰度发布架构设计讲明白了

帮助安全红队取得成功的11条建议

Mysql 5.7 into the pit

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules

PMP有什么答题技巧?

Force buckled brush problem record 7.1 -- -- -- -- -- 707. The design list

Flume (四) --------- Flume 企业开发案例

etcd实现大规模服务治理应用实战
随机推荐
MT4/MQL4入门到精通EA课程第二课-常用的功能函数
力扣刷题记录9.1-----24. 两两交换链表中的节点
2020.10.13开发日志
【HNUMSC】C language second lecture
2022中国眼博会,中国北京国际儿童青少年眼睛健康产业展览会
yii2的安装之路
.reduce()的简单例子
JDBC technology (2) - set up common sql and configuration files
mysql 5.7 入坑
10.1-----19. Delete the Nth node from the bottom of the linked list
Electromagnetic radiation safety standards and detection methods
物联网未来:未来五年的预期
数据恢复软件EasyRecovery支持恢复所有类型的文件
MAYA发动机建模
Line segment tree of knowledge
Design of Go-7-RESTful API
力扣刷题记录1.5-----367. 有效的完全平方数
软件开发之我的一点想法
年金险的安全性怎么样啊?可靠吗?
2022 Eye Care Products Exhibition, Beijing Eye Health Exhibition, Ophthalmology Exhibition, Myopia Correction Equipment Exhibition