package com.xxx.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class File2Code {
/**
* <p>将文件转成base64 字符串</p>
* @param path 文件路径
* @return
* @throws Exception
*/
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>
* @param base64Code
* @param targetPath
* @throws Exception
*/
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>
* @param base64Code
* @param targetPath
* @throws Exception
*/
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:\\00.xlsx");
System.out.println(base64Code);
decoderBase64File(base64Code, "D:\\22.xls");
toFile(base64Code, "D:\\three.txt");
} catch (Exception e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
base64将文件(图片或其它)转码成字符串,将字符串还原成文件
c#中 base64字符串与普通字符串互转,转成 Base64 形式的...
VB将二进制图片文件转换为Base64字符串文本,可直接将字符串加密,也可直接读取数据库或图片文件加密为Base64字符串!
将图片转成Base64字符串。供前端Html <img/> 使用 将转换结果替换至src的值就OK了
VB 将二进制图片文件转换为Base64字符串文本
VB 将二进制图片文件转换为Base64字符串文本,再将 BASE64转成图片,亲测,运行正常VB6.0
java 把PDF转换成BASE64,java 把PDF转换成BASE64,java 把PDF转换BASE64,java 把PDF转换成BASE64java 把PDF转换成BASE64
VB6将二进制图片文件转换为Base64字符串文本,可直接将字符串加密,也可直接读取数据库或图片文件加密为Base64字符串!
C# 文件转base64 文件转换 C# 文件转base64 文件转换
Java 从网络中读取图片 转换成Base64字符串
获取任意文件的base64字符串源码,js版。
图片与Base64加密码字符串相互转换工具 带源码
File Base64 File Base64 File Base64 File Base64 文件转化为base64字符串
文件为可执行工具,基于.Net,内含使用说明和样例。 功能为,将保存base64数据的文本文件,转换成对应的二进制文件 可广泛应用于html内嵌图片提取、eml附件提取、http数据流转文件等等。
base64序列化字符串,用于传输,避免传输过程中转义符错误。
输入后,单击“确定”,图像将被转换为Base64字符串,并将其写入名为output.py的文件中。 为什么要这样做? 如果您正在开发GUI程序,有时更容易将所有资产与源代码本身一起包含在文件中。 这将使您能够通过提供一...
Base64图片例子位图到Base64字符串Base64Image .encode(bitmap) { base64 -> base64?. let { // success }}Base64字符串到位图Base64Image .decode(base64, { bitmap -> bitmap?. let { // success }})安装...
php base64字符串图片jpeg文本文件转换为jpeg图片
c#字符串转为base64的程序,或base64转为字符的工具,比较简单.
用途:根据图片文件(PNG/JPG/BMP),生成对应的Base64字符串文件。 可以选择设置,转换时的图片质量参数(Quality)。 这个小小工具,只是针对Base64字符串的浅显技术研究与实验。 用C# .NET语言编写,运行时需要...