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 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

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

Joined: Feb 25, 2007
Posts: 1638

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

apigee, a better way to API!
I agree. Here's the link:
subject: Convert byte stream to int
It's not a secret anymore!