file io - Reading 32 bit binary numbers in java -


I am trying to read five 32-bit binary numbers. I am reading 1, 5, 8 and 45 properly, but I can not read 134,217,728. My code is as follows:

  FileInputStream file = new FileInputStream ("C: /Sn3.edf"); BufferedInputStream buff = new BufferedInputStream (file)) {int in; For (int i = 0; i   

I tried to change int for a long time but did not work. Any help is appreciated

You did not post a complete code example and you did not have your input file The content was not posted, but it goes anyway.

According to JDK docs, BufferedInputStream.read () returns a byte at a time. You are reading a byte at a time, storing it in in , and printing it in the console. This code will work only for you if your number is 8 bits in size. Since you have a 32-bit integer file stored in it, you will need to read 4 bytes in one time (32 bit / 8 bits / byte) and then do some math to get those bytes in Java int .

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -