将文件转成base64 字符串
来源:互联网 发布:淘宝的运行模式 编辑:程序博客网 时间:2024/05/16 23:50
public
class
FileCode {
/**
* <p>将文件转成base64 字符串</p>
* @param path 文件路径
*/
public
static
String encodeBase64File(String path)
throws
Exception {
File file =
new
File(path);
FileInputStream inputFile =
new
FileInputStream(file);
byte
[] buffer =
new
byte
[(
int
)file.length()];
inputFile.read(buffer);
inputFile.close();
return
new
BASE64Encoder().encode(buffer);
}
/**
* <p>将base64字符解码保存文件</p>
*/
public
static
void
decoderBase64File(String base64Code,String targetPath)
throws
Exception {
byte
[] buffer =
new
BASE64Decoder().decodeBuffer(base64Code);
FileOutputStream out =
new
FileOutputStream(targetPath);
out.write(buffer);
out.close();
}
/**
* <p>将base64字符保存文本文件</p>
*/
public
static
void
toFile(String base64Code,String targetPath)
throws
Exception {
byte
[] buffer = base64Code.getBytes();
FileOutputStream out =
new
FileOutputStream(targetPath);
out.write(buffer);
out.close();
}
public
static
void
main(String[] args) {
try
{
String base64Code =encodeBase64File(
"D:\\1.jpg"
);
System.out.println(base64Code);
decoderBase64File(base64Code,
"D:\\2.jpg"
);
toFile(base64Code,
"D:\\three.txt"
);
}
catch
(Exception e) {
e.printStackTrace();
}
}
}
0 0
- 将文件转成base64 字符串
- 将文件转成编码base64码
- 【20171127】HTML5 上传文件(向后台传base64Code--[将文件转成base64 字符串])
- strus2中Action方法将 base64 字符串转成 图片文件实体
- android将图片转成字符串,再将字符串转成图片 (base64处理的字符串)
- 将PDF格式文件转成二进制并生成Base64编码,将Base64编码转成PDF文件
- 将图片转成base64
- php 将图片文件转成base64编码的方法
- 文件转成base64
- [Java学习] 将PDF格式文件转成二进制并生成Base64编码,将Base64编码转成PDF文件
- [Java学习] 将PDF格式文件转成二进制并生成Base64编码,将Base64编码转成PDF文件
- 将file文件内容转成字符串
- java将base64转成image
- 将图片文件流转换成base64字符串
- UIImage图片转成Base64字符串
- 将图片转成base64字符串并在JSP页面显示的Java代码
- 将字符串转成列
- 将字符串转成十六进制
- 匿名hash
- ST-LINK
- Python简单介绍
- android中HTTP协议访问网络及其方式及其http的GET和POST的优缺点
- 时钟小结
- 将文件转成base64 字符串
- 深入理解Calendar的set和get方法
- 软件开发部分文档说明
- C语言的语句
- Hibernate 配置
- python学习笔记
- 常用CSS样式属性
- C代码编译过程分析
- 【JQuery】——可编辑的表格