Base64编码:非法的base64字符3c [英] Base64 Encoding: Illegal base64 character 3c
本文介绍了Base64编码:非法的base64字符3c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将xml格式的数据解码为字节base64
,但是遇到问题.我的方法是在Java中,它使用String
数据并将其转换为bytes
,就像波纹管一样.
I am trying to decode data in an xml format into bytes base64
and I am having an issues. My method is in java which takes a String
data and converts it into bytes
like as bellow.
String data = "......"; //string of data in xml format
byte[] dataBytes = Base64.getDecoder().decode(data);
哪个失败了,并给出了类似波纹管的异常.
Which failed and gave the exception like bellow.
java.lang.IllegalArgumentException: Illegal base64 character 3c
at java.util.Base64$Decoder.decode0(Base64.java:714)
at java.util.Base64$Decoder.decode(Base64.java:526)
at java.util.Base64$Decoder.decode(Base64.java:549)
at XmlReader.main(XmlReader.java:61)
xml格式与base64
不兼容吗?
Is the xml format not compatible with base64
?
推荐答案
感谢@ luk2302,我能够解决此问题.在解码字符串之前,我需要先将其编码为Base64
Thanks to @luk2302 I was able to resolve the issue. Before decoding the string, I need to first encode it to Base64
byte[] dataBytes = Base64.getEncoder().encode(data.getBytes());
dataBytes = Base64.getDecoder().decode(dataBytes);
这篇关于Base64编码:非法的base64字符3c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文