why Java throws a NumberFormatException

前端 未结 3 923
灰色年华
灰色年华 2021-01-15 10:46

I got an exception while parsing a string to byte

String Str =\"9B7D2C34A366BF890C730641E6CECF6F\";

String [] st=Str.split(\"(?<=\\\\G.{2})\");

byte[]by         


        
3条回答
  •  死守一世寂寞
    2021-01-15 11:11

    Assuming you want to parse the string as hexadecimal, try this:

    bytes[i] = Byte.parseByte(st[i], 16);
    

    The default radix is 10, and obviously B is not a base-10-digit.

提交回复
热议问题