三张扑克亚洲首选288x,黄粉虫养殖技术,冷皇的废后番外
编写代码之前先来介绍一下我们要用到的两个包;
commons-codec-1.10.jar
commons项目中用来处理常用的编码方法的工具类包,例如des、sha1、md5、base64,url,soundx等等。
commons-exec-1.3.jar
apache commons exec 是 apache 上的一个 java 项目,提供一些常用的方法用来执行外部进程
你可以到本站直接下载 apache commons 官方包
下面看一下代码结构:
import org.apache.commons.codec.binary.base64; import org.apache.commons.codec.digest.digestutils; /** * @author delver_si * */ public class encodeanddecode { /** * md5加密 * @param str * @return */ public static string md5encode(string str) { return digestutils.md5hex(str); } /** * base64加密 * @param str * @return */ public static string base64encode(string str) { byte[] b = base64.encodebase64(str.getbytes(), true); return new string(b); } /** * base64解密 * @param str * @return */ public static string base64decode(string str) { byte[] b = base64.decodebase64(str.getbytes()); return new string(b); } /** * 生成sha1 */ public static string sha1encode(string str) { return digestutils.sha1hex(str); } }
把主要功能都放在一个类文件中
新建test类引用上个文件
import security.encodeanddecode; import security.exec; public class test { public static void main(string[] args) { system.out.println(encodeanddecode.md5encode("jb51.net"));//md5加密 system.out.println(encodeanddecode.base64encode("jb51.net"));//base64加密 system.out.println(encodeanddecode.base64decode("ami1ms5uzxq="));//base64解密 string str = exec.exec("ping jb51.net");//执行系统的ping命令 system.out.println(str); } }
好了 ,运行一下看看最终结果
这些只是apache commons 包的基本功能,其它功能大家可以到这里下载 apache commons 使用说明 中文word版 详细研究
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论