• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Read Bytes From DataInputStream

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!