最近在做项目中遇到base64code处理的问题。下面是我写的示例:
package com.juck.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class Base64Code{
//测试主方法
public static void main(String[] args){
final String fileName = "示例文件";
final String fileSuffix = ".jpg";
final String url = "XXXXXXX";//文件路径
try{
String base64Code=encoderToBase64Code(url);
base64CodeToFile(base64Code,"D:\\BASE64编码字符串"+fileName+".txt");
decoderToBase64Code(base64Code,"D:\\解码"+fileName+fileSuffix);
}catch(Exception e){
e.printStackTrace();
}
}
//文件转换程BASE64编码
public static String encoderToBase64Code(String path)throws IOException{
File file = new File(path);
FileInputStream input = new FileInputStream(file);
byte[] buffer = new byte[(int)file.length()];
input.read(buffer);
input.close();
System.out.print(new BASE64Encoder().encode(buffer));//打印文件经过编码后的字符串
return new BASE64Encoder().encode(buffer);
}
//BASE64字符串解码并保存文件
public static void decoderToBase64Code(String base64Code,String targetPath) throws IOException{
byte[] buffer = new BASE64Decoder().decodeBuffer(base64Code);
FileOutputStream out = new FileOutputStream(targetPath);
out.write(buffer);
out.close();
//BASE64字符串保存成文本
public static void base64CodeToFile(String base64Code,String targetPath) throws IOException{
byte[] buffer = base64Code.getBytes();
FileOutputStream out = new FileOutputStream(targetPath);
out.write(buffer);
out.close();
}
}
}
http://juck.iteye.com
分享到:
相关推荐
java自学基础和高级部分的代码,30天的内容,多敲才是学习的真理,全部敲完并理解,就算入门java了,转自尚硅谷
java base64 源码 java-web-services-binary
javaweb中文件的上传和下载,BASE64编码的实现,以及javamail的具体应用。提供了完整的源码和实现,希望对大家有所帮助。
java jdk源码 jdk8-base-source-code jdk8 中的 java.base的源码学习.
java几个类实现base64编码、解码工作,可放入开发程序中,快速使用。
1、缺少sun.misc.BASE64Encoder的JAR包的问题 右键项目--》Java Build Path--->Libraries---->点开 JRE System Library[...]---》选中Access rules defined...----》edit----》Add--->选Accessible--->填** 2、 调...
Base64加密需要的Bouncy Castle和Commons Codec的jar包(commons-codec-1.10.jar、bcprov...文章名称:数据加解密基础知识介绍,及Java实现Base64加密,链接:https://blog.csdn.net/slvayf/article/details/83377834。
* 编码工具类 * 1.将byte[]转为各种进制的字符串 * 2.base 64 encode * 3.base 64 decode * 4.... * 5.... * 6.结合base64实现md5加密 ... * 8.AES加密为base 64 code * 9.AES解密 * 10.将base 64 code AES解密
Various javaUntils integration tool class source code, decompressed cv directly used: Base64ImageUtils.java ConfigUtils.java DateUtils.java DesEncryptUtils.java EncryptUtils.java ExcelBigDataUtils....
javabase0 Automatically exported from code.google.com/p/javabase0 从google code迁移过来的工程 Java的基础类代码
java编码转换源码 BaseConversion Base Conversion Android App source code and layout files, made using Java and XML in Android Studio.
Java Platform Standard Edition 7 Documentation What's New Documentation Release Notes Tutorials and Training The Java Tutorials Java Training More Information Java SE 7 Names and ...
9. Java Base System and Libraries 9.1Java Language Classes 9.2Input Output Package 9.3Utility Package 9.4Abstract Window Toolkit 10. The HotJava World-Wide Web Browser 10.1The ...
说明:Various javaUntils integration tool class source code, decompressed cv directly used: Base64ImageUtils.java ConfigUtils.java DateUtils.java DesEncryptUtils.java EncryptUtils.java ...
• We redesigned the entire code base to increase clarity of presentation and consistency in style and convention, including reliance on type inference, as introduced in Java 7, to reduce clutter when...
base64图像。 您可以将其共享到任何不支持代码的网站-该网站不支持markdown或<pre><code>标记或任何其他可以使您的帖子中包含任何代码块的内容。 它比截屏好得多,因为您可以从非常大的代码文件中选择单个图像。 ...
本工程可以直接使用,而且与IOS,Android,JAVA,.NET 已调通。 主要用于客户端进行通信,数据之间地安全性。对数据进行加密和解密 AES加密有多种算法模式,下面提供两套模式的可用源码: 一、CBC(Cipher Block ...
BASE64 严格地说,属于编码格式,而非加密算法 MD5(Message Digest algorithm 5,信息摘要算法) SHA(Secure Hash Algorithm,安全散列算法) HMAC(Hash Message Authentication Code,散列消息鉴别码)
将指定图片url转base64code编码,返回string类型的,里面是通过流写的
java8 看不到源码基节点 BASE-NODE 是 BASE 平台中 Node 组件的实现。 皮棉: 如果您使用 IntelliJ IDEA,您可以调用gradlew installKtlintIdeaProject来配置代码样式。 您也可以从根目录 'kotlin-codestyle.xml' ...