| Author |
Hex Dump to byte array
|
Ahmed Basheer
Ranch Hand
Joined: Apr 15, 2004
Posts: 77
|
|
I would need to read a text file and convert a each hex dump line to byte array. Are there any build-in routines in java which will do this. e.g the file looks like --------------example.txt--------- # this is first message 00 35 01 01 00 1f # This is the 2nd message 00 87 71 aa 1a a1 ----------------------------------- 00 35 01 01 00 1f needs to converted to one byte array and 00 87 71 aa 1a a1 to another byte array. Your suggestions will be appreciated. String.getBytes() doesn't seem to be working. Basheer
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
You can parse each line with a StringTokenizer - each token will be a 2 character hex number. Use Integer.parseInt( string, radix ) where radix = 16 for hex parsing. Cast the resulting int to byte. Bill
|
Java Resources at www.wbrogden.com
|
 |
 |
|
|
subject: Hex Dump to byte array
|
|
|