Java对图片Base64转码——HTML对Base64解码「Java加强版」

Java对图片Base64编码
package base64;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Scanner;
import javax.imageio.ImageIO;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class imageToBase64 {
static BASE64Encoder encoder = new sun.misc.BASE64Encoder();
static BASE64Decoder decoder = new sun.misc.BASE64Decoder();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in) ;
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** 欢迎使用W_Jp的Base64编码 **\n");
System.out.printf("\t\t*********************************************\n");
System.out.printf("输入图片地址:");
String path = scanner.next() ;
if(!getImageBinary(path).equals(""))
{
System.out.printf("\n" + getImageBinary(path) + "\n\n");
System.out.printf("是否导出内容?(Y/N):");
String boo = scanner.next() ;
if(boo.equals("Y") || boo.equals("y")){
System.out.println();
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** 1.导出现Base64编码到TXT文档 **\n");
System.out.printf("\t\t** 2.导出Base64解码后的png图片 **\n");
System.out.printf("\t\t** 3.同时操作以上两个 **\n");
System.out.printf("\t\t*********************************************\n");
System.out.printf("输入您的选择:");
boo = scanner.next() ;
if(boo.equals("1")){
System.out.println();
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** 温馨提示:导出后文件名为wjp.txt **\n");
System.out.printf("\t\t*********************************************\n");
System.out.printf("输入Base64编码的导出地址:");
String toTxtPath = scanner.next() ;
if(base64StringToTxt(getImageBinary(path), toTxtPath).equals("success")){
System.out.println();
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** 导出成功 **\n");
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** Thanks!!! **\n");
System.out.printf("\t\t↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑\n");
}
} else if(boo.equals("2")){
System.out.println();
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** 温馨提示:导出后文件名为wjp.png **\n");
System.out.printf("\t\t*********************************************\n");
System.out.printf("输入解码后图片的导出地址:");
String toImgPath = scanner.next() ;
if(base64StringToImage(getImageBinary(path), toImgPath).equals("success")){
System.out.println();
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** 导出成功 **\n");
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** Thanks!!! **\n");
System.out.printf("\t\t↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑\n");
}
} else if(boo.equals("3")){
System.out.println();
System.out.printf("\t\t*********************************************\n");
System.out.printf("\t\t** 温馨提示:导出后文件名为wjp.txt/wjp.png **\n");
System.out.printf("\t\t*********************************************\n");

推荐阅读