File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Read Bytes From DataInputStream" Watch "Read Bytes From DataInputStream" New topic
Author

Read Bytes From DataInputStream

Joey Stuart
Greenhorn

Joined: Nov 05, 2009
Posts: 2
Hi,
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
Greenhorn

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.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read Bytes From DataInputStream
 
Similar Threads
Reading your Data File
Error printing out from a read in file.
Reading the first 10 bytes of a file
Some questions about writeBytes(String) vs writeChars(String)
To Hex String and back...