aspose file tools*
The moose likes I/O and Streams and the fly likes Convert byte stream to int 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 "Convert byte stream to int" Watch "Convert byte stream to int" New topic
Author

Convert byte stream to int

Ashish Malik
Ranch Hand

Joined: Jul 11, 2010
Posts: 50
Hi, i m tryin to send some integer data over bluetooth.
I am sending it as a byte but want to convert it at reciever end to the original integer that was sent.

The sender code snippet is as follows:


The code for reciever is like this:



Sending and recieving works fine!
Ashish Malik
Ranch Hand

Joined: Jul 11, 2010
Posts: 50
Found the way...
instead of using InputStream and OutputStream...i used
DataInputStream and DataOutputStream...they got methods as...writeInt() and readInt()

But anyways where DataInputStream cannot be used and we have to use InputStream what to do then!
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

You can use a ByteBuffer to read primitives from a byte array.


apigee, a better way to API!
 
jQuery in Action, 2nd edition
 
subject: Convert byte stream to int