A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
FileInputStream & Negative Bytes...
Joined: May 08, 2005
May 20, 2005 03:50:00
Is there a way to have a file input stream not return negative values? Currently I'm using one to read a file that starts with the bytes:
6F 61 FE
The integer output of these should be: 111, 97, 254 repectively. However, I'm getting: 111, 97, -2. Is there a method that reads unsigned bytes like in the ImageInputStream Class?
author and iconoclast
Joined: Jul 08, 2003
May 20, 2005 05:55:00
All bytes are signed in
. You can convert a byte to its unsigned integer representation if you need to like this:
FileInputStream fis = ... byte bytes = new byte; fis.read(bytes); for (int i=0; i<100; ++i) System.out.println(bytes[i] & 0xFF);
[Jess in Action]
It is sorta covered in the
JavaRanch Style Guide
subject: FileInputStream & Negative Bytes...
How a character save in 2 bytes in Java?
stopping JSP execution temporarily through code ....please help
100 times "hello world" without loop or recursive
Open in New Window from selected item in list box
Help please, what is wrong here.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014