먼저 배열이를 사용하여 바이트 열로 변환
String line= new String(Arrays.toString(your_array))
을 수행하여, 그 다음을 보내고
public static byte[] StringToByteArray(String line)
{
String some=line.substring(1, line.length()-1);
int element_counter=1;
for(int i=0; i<some.length(); i++)
{
if (some.substring(i, i+1).equals(","))
{
element_counter++;
}
}
int [] comas =new int[element_counter-1];
byte [] a=new byte[element_counter];
if (a.length==1)
{
a[0]= Byte.parseByte(some.substring(0));
}
else
{
int j=0;
for (int i = 0; i < some.length(); i++)
{
if (some.substring(i, i+1).equals(","))
{
comas[j]=i;
j++;
}
}
for (int i=0; i<element_counter; i++)
{
if(i==0)
{
a[i]=Byte.parseByte(some.substring(0, comas[i]));
}
else if (i==element_counter-1)
{
a[i]=Byte.parseByte(some.substring(comas[comas.length-1]+2));
}
else
{
a[i]=Byte.parseByte(some.substring(comas[i-1]+2, comas[i]));
}
}
}
return a;
}
아래 기능을 사용할 수를 적절한 문자열로 바이트 배열의 convertion을 stringToConvert = "이 문자열은 76 자이며 바이트 배열로 변환됩니다."; 바이트 [] theByteArray = stringToConvert.getBytes(); –
W0JAM2U0YTlhN2Q = [B @ 3e4a9a7d에 대한 Base64, 자바의 바이트 배열에 대한 문자열 표현처럼 보입니다. 직접 바이트 조작을 수행하는 경우 잘못된 데이터를 전송할 수 있으므로 다시 확인하십시오. – mdrg
out은 내 바이트 배열이고 인쇄 될 때 내 예제 출력의 첫 번째 줄을 제공합니다. out.toString() 확실히 날 준다 [B @ 3e4a9a7d – Mitch