This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes FileInputStream & Negative Bytes... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "FileInputStream & Negative Bytes..." Watch "FileInputStream & Negative Bytes..." New topic

FileInputStream & Negative Bytes...

Robert Elam

Joined: May 08, 2005
Posts: 10
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?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Hi Robert,

All bytes are signed in Java. You can convert a byte to its unsigned integer representation if you need to like this:

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: FileInputStream & Negative Bytes...
Similar Threads
Open in New Window from selected item in list box
How a character save in 2 bytes in Java?
100 times "hello world" without loop or recursive
Help please, what is wrong here.
stopping JSP execution temporarily through code ....please help