File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Read Bytes From DataInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Read Bytes From DataInputStream" Watch "Read Bytes From DataInputStream" New topic

Read Bytes From DataInputStream

Joey Stuart

Joined: Nov 05, 2009
Posts: 2
I'm having an issue reading binary data over a socket. I'm using DataInputStream to read in the data and I'm able to print it out in Hex, but not in any kind of human readable format. Here is what I'm trying to read in and the code I'm using.

I'm supposed to read in one byte with a value of "S".

Here is the code

This code prints out HEX: 4e, which is what I'm expecting, but how would I convert the byte to make it print out the letter "S"?

Thanks for any help in advance.

Joey Stuart

Joined: Nov 05, 2009
Posts: 2
Ok, I figured that out by using this code instead.

That works great, my only question is now how would I read in and print different data types? For instance the next two values I'm supposed to read in are type short(which contains two bytes and a value of 0x0012) and type String. I'm also able to print out the expected values in HEX if that helps.

I agree. Here's the link:
subject: Read Bytes From DataInputStream
It's not a secret anymore!