请问如何将String转换为Byte[]? 
例如:12345678 
能够转换为 {0x12,0x34,0x56,0x78} 
注意:不是需要s.getBytes() 
谢谢回帖  
 

解决方案 »

  1.   

    1, How to split that long String to a list of short Strings?
    12345678 ==> 12, 34, 46, 782, How to create a byte value from a short String?
    "12" ==> 0x12 ==> 18 in decimal.
      

  2.   

    String str="12345678";
    String str0=str.substring(0,2);
    String str1=str.substring(2,2);
    String str2=str.substring(4,2);
    String str3=str.substring(6,2);byte[] result=new byte[]{Byte.parseByte(str0,16),Byte.parseByte(str1,16),Byte.parseByte(str2,16),Byte.parseByte(str3,16)};
      

  3.   

    修正下
    String str0=str.substring(0,2);
    String str1=str.substring(2,4);
    String str2=str.substring(4,6);
    String str3=str.substring(6,8);