wood burning stoves
The moose likes Beginning Java and the fly likes Read/Write ints using 2bytes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Read/Write ints using 2bytes" Watch "Read/Write ints using 2bytes" New topic

Read/Write ints using 2bytes

Lora Tully

Joined: Nov 29, 2004
Posts: 8
Hi. I was wondering if anyone can help me read and write one interger using two bytes. I have an interger between 500-800 that I need to write. Normally I would use...


But as 500 is above one byte (256) I was wondering how to write this, and then later read it back.
As since one int would be spread over two bytes, I have no idea how to read it, normally I would use


And I have no idea how to do this. Can anyone help me please?
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Try DataOutputStream.writeShort() and DataInputStream.readShort()

Mike Gershman
SCJP 1.4, SCWCD in process
Lora Tully

Joined: Nov 29, 2004
Posts: 8
Thanks that works great!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Read/Write ints using 2bytes
It's not a secret anymore!