This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Similar Threads
To Hex String and back...
Error printing out from a read in file.
Reading your Data File
Reading the first 10 bytes of a file
Some questions about writeBytes(String) vs writeChars(String)