我有我的Base64解码器:
public class Decoder {
public static void Decode() throws IOException{
String s = "";
String output = "";
Scanner sc = new Scanner(new File("C:\\Users\\Dragon\\Desktop\\Binary\\Base64.txt"));
while (sc.hasNextLine()) {
s += sc.nextLine();
System.out.println(s);
}
sc.close();
byte[] bytes = Base64.decodeBase64(Files.readAllBytes(Paths.get("C:\\Users\\Dragon\\Desktop\\Binary\\Base64.txt")));
Writer out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("C:\\Users\\Dragon\\Desktop\\Binary\\Base64.png"), "UTF8"));
for(int i =0; i < bytes.length; i++){
output+=bytes[i];
out.write(bytes[i]);
System.out.println((char)bytes[i]);
}
out.close();
System.out.println("Your File has been saved at C:\\Users\\Dragon\\Desktop\\Binary\\Base64.png");
}
}
当我输入
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGHRFWHRBdXRob3IAbWluZWNyYWZ0aW5mby5jb23fZidLAAAAsklEQVQ4y2P4//8/AyUYwUADPOYG/5ExujxeA0Aa0AG6ITgNgGle9O05HF/89fm/we29KIZgNQCmGaQBphkEvN5eBGOiDYBpBBkEwyADkF2BYQC65p4vj1CwwtRGFFfgNQBkIy4DYK7AaQBIs87ZjVgNkK7OBmO8BsACDKQBGYMMBWEQG6sBsEAEaQbZAtMAwzAxnGEAMwDkR1wGwGwnmJCQnYzudKKTMjaMNylTnBvJxQAdEGHNXhVMiwAAAABJRU5ErkJggg==
进入它我得到:
ノPNG
IHDR a tEXtAuthor minecraftinfo.comf'K ᄇIDAT8ᅨc?%@<₩ム1ᄎ<^@ᄎ!8
タi^■9_■ᄑ(ニ`5 ᆭᄂᆭᄐ^cᄁ
タiᅢ ミ]チa ᄎ₩゙/マPᄚᅡᅯFW¢5 d#.`ᆴi H뽸ヘX
ミᆴᅫcᄐᄂテaᆱᄚ@iᅮ ᅢ01ワa 3 ¦G\l'リミミンフ○tᄁモ26フ7)Sワᅤ aᅪ^Lヒ IENDᆴB`ツ
预期的输出是:
‰PNG
IHDR óÿa tEXtAuthor minecraftinfo.comßf'K ²IDAT8Ëcøÿÿ?%Á@<æÿ‘1º<^@к!8
€i^ôí9_üõù¿Áí½(†`5 ¦¤¦¼Þ^c¢
€ià ]a ºæž/P°ÂÔFWà5 d#.`®Ài H³ÎÙX
®Îc¼À¤ƒa«°@iÙÓ Ã01œa 3 äG\Àl'˜Œît¢“26Œ7)SœÉÅ aÍ^L‹ IEND®B`‚
我知道我的编码器工作正常,因为当我把我的
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGHRFWHRBdXRob3IAbWluZWNyYWZ0aW5mby5jb23fZidLAAAAsklEQVQ4y2P4//8/AyUYwUADPOYG/5ExujxeA0Aa0AG6ITgNgGle9O05HF/89fm/we29KIZgNQCmGaQBphkEvN5eBGOiDYBpBBkEwyADkF2BYQC65p4vj1CwwtRGFFfgNQBkIy4DYK7AaQBIs87ZjVgNkK7OBmO8BsACDKQBGYMMBWEQG6sBsEAEaQbZAtMAwzAxnGEAMwDkR1wGwGwnmJCQnYzudKKTMjaMNylTnBvJxQAdEGHNXhVMiwAAAABJRU5ErkJggg==
进入本网站: http://www.base64decode.org/我得到了预期的输出。我的解码器出了什么问题?