• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileInputStream & Negative Bytes...

 
Robert Elam
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Robert,

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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic