I am reading bytes as follows:
try(FileInputStream f = new FileInputStream("nameOfFile")){
int readByte = 0;
int mask =0b111;
while((readByte=f.read())!=-1) {
System.out.println(Integer.toBinaryString(readByte & mask));
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
However, when i try to obtain the 8 bits that forms the number, sometimes I get 7 bits or even more bits than 8. Can anyone help me with this problem? I want to get 8 bits so after that i can look at first 3 bits for example. I need that for returning the charset in this method.
I'll be very gratefull if you help me. I am looking forward to hearing from you soon.
Best regards, WaterKnight