Base64
2016-08-05 18:39
239 查看
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation.
Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that is designed to deal with textual data.
用到java包
小样
打印结果:
Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that is designed to deal with textual data.
用到java包
<dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.10</version> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency>
小样
import java.io.UnsupportedEncodingException; import net.sf.json.JSONArray; import org.apache.commons.codec.binary.Base64; public class Test { public static void main(String[] args) throws UnsupportedEncodingException{ // 工具 Base64 base64 = new Base64(); // 现有byte[] byte[] bytes = new byte[] { -25, -69, -76, -27, -97, -70, -25, -103, -66, -25, -89, -111 }; // 转成字符串,存储或者传输 String s = base64.encodeAsString(bytes); // 57u05Z+655m+56eR // 待使用byte[] 时,将字符串解码 bytes = base64.decode(s); System.out.println(JSONArray.fromObject(bytes).toString()); // 原始byte[] 是这样的 System.out.println(new String(bytes, "utf-8")); } }
打印结果:
[-25,-69,-76,-27,-97,-70,-25,-103,-66,-25,-89,-111] 维基百科
相关文章推荐
- java 2 8 10 16
- POJ 2367 Genealogical tree (拓扑排序)
- java 数据类型
- Tomcate环境变量配置
- adb 和 shell、Logcat 常用命令
- leetcode_c++:Longest Common Prefix(014)
- android艺术开发探索之消息机制
- Android EasyClient 云台控制开源流媒体摄像机EasyCamera
- String 和 byte[]
- 数组重复值和数组去重
- properties.load(in); 引出的中文乱码问题
- JAVA 反射应用:properties2Object
- 图结构练习——最短路径
- JS 之 innerHTML
- 关于PHP执行超时的问题
- telnet连接redis和redis-cli连接redis
- 前端本地客户端压缩图片,兼容IOS,Android,PC、自动按需加载文件
- CommandLine 和 Options
- MAT(2)安装Memory Analyzer
- java tools: jmap