📄 base64.java
字号:
//BASE加密类
package com.neck.math;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.FileNotFoundException;
import java.util.Scanner;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class BASE64
{
//将s进行BASE64编码
public static String getBASE64EncoderStr(String s) throws UnsupportedEncodingException
{
if (null == s)
return null;
else
return new BASE64Encoder().encode(s.getBytes());
}
//将s进行BASE64解码
public static byte[] getBASE64DecoderBt(String s) throws IOException
{
if (null == s)
return null;
else
{
BASE64Decoder decoder = new BASE64Decoder();
return decoder.decodeBuffer(s);
}
}
//将指定文件用BASE64编码
public static void changeToBASE64(String filePath) throws IOException
{
Scanner sc = new Scanner(new FileInputStream(filePath)).useDelimiter(" ");
PrintWriter pw = new PrintWriter(filePath + "_BASE64_");
while (sc.hasNext())
{
pw.println(getBASE64EncoderStr(sc.next()));
}
sc.close();
pw.close();
}
//将指定文件从BASE64解码
public static void recoverFromBASE64(String filePath) throws IOException, FileNotFoundException
{
Scanner sc = new Scanner(new FileInputStream(filePath)).useDelimiter(" ");
PrintWriter out = new PrintWriter(filePath.substring(0, filePath.indexOf("_BASE64_")));
while (sc.hasNext())
{
out.println(new String(getBASE64DecoderBt(sc.next()), "GB2312"));
}
sc.close();
out.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -