-1
当我使用Base64.encode(bytearray,Base64.DEFAULT)编码我的字节数组时,所以此方法的结果将最后加10在结果字节数组中的项目,当我将这个结果字节数组转换成字符串比10将转换为\ n(换行符)在末尾 请让我知道为什么\ n将追加末尾Base64.encode(bytearray,Base64.DEFAULT)此方法的结果将在最后一项添加10
下面是将字符串转换为字节数组的代码
int inLength = hexValue.length();
int i, o = 0;
long outByte = 0;
byte[] outBytes = new byte[(inLength/2)];
for (i = 0; i < inLength; i++) {
char c = hexValue.charAt(i);
int value = -1;
if (c >= '0' && c <= '9')
value = (c - '0');
else if (c >= 'A' && c <= 'F')
value = 10 + (c - 'A');
else if (c >= 'a' && c <= 'f')
value = 10 + (c - 'a');
if (value >= 0) {
if (i % 2 == 1) {
outBytes[o++] = (byte) ((outByte << 4) | value);
outByte = 0;
} else {
outByte = value;
}
} else {
if (o != 0)
break;
}
}
return outBytes;
如何创建字节数组? – hexafraction
你确定额外的换行符还没有在那里? – Thilo
@hexafraction下面是代码,我只是将字符串传递到此代码,这将返回该字节数组之后,我编码此数组 \t \t byte [] outBytes = new byte [(inLength/2)]; \t \t for(i = 0; i = '0' &&ç<= '9') \t \t \t \t值=(C - '0'); \t \t \t否则如果(C> = 'A' &&ç<= 'F') \t \t \t \t值= 10 +(C - 'A'); \t \t \t否则如果(C> = 'A' &&ç<= 'F') \t \t \t \t值= 10 +(C - 'A'); \t \t \t如果(值> = 0){ \t \t \t \t如果(ⅰ%2 == 1){ \t \t \t \t \t outBytes〔O ++] =(字节)((outByte << 4)|值); \t \t \t \t \t outByte = 0; \t \t \t \t}其他{ \t \t \t \t \t outByte = VALU –