aspose file tools
The moose likes Java in General and the fly likes Hex Dump to byte array Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Hex Dump to byte array" Watch "Hex Dump to byte array" New topic
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
    
    1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hex Dump to byte array
 
Similar Threads
javax.xml.ws.WebServiceException: Failed to access the WSDL
ftps in java
Formlogin/Apache/SSL
java.io.IOException: unsupported keyword
Where is private key?