Java中Base64解码


某个程序员闯关游戏的最后一关,有点费事,需要将一个二进制文件转换成ascii码,发现ascii码文件是Base64的加密文件,所以再用BASE64Decoder包(下载地址:https://pan.baidu.com/s/1slEQitf)进行Base64解码,得到的文件是一个压缩文件。

代码如下:

import Decoder.BASE64Decoder;

public class d1111 {

	 public static void main(String[] args) throws IOException { 
		 game1111_9();
	 }
	 public static void game1111_9() throws IOException {
		 File file = new File("C:\\Users\\光\\Pictures\\11.txt");
		 BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
		 StringBuffer sb = new StringBuffer();
		 String line = null;
		 while ((line = br.readLine()) != null) {
			 String[] codes=line.split(" ");
			 for(String code:codes){
				 char c=(char) Integer.parseInt(code, 2);
				 sb.append(c);
			 }
		 }
		 System.out.println(sb);
		 BASE64Decoder decoder = new BASE64Decoder();
		 byte[] decodeBuffer = decoder.decodeBuffer(sb.toString());
		 File decodeFile = new File("C:\\Users\\光\\Pictures\\decode.tar.gz");
		 FileOutputStream fileOutputStream = new FileOutputStream(decodeFile);
		 fileOutputStream.write(decodeBuffer);
		 fileOutputStream.close();
		 br.close();
	 }
	 
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值