This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Without knowing what is in the file, it's impossible to say what you are doing wrong.
But my guess is that your file contains some text which represents an integer, as opposed to 32 bits which represent an integer, and you were assuming that the readInt() method was meant for the first case instead of for the second case.
Thank you very much!
I still have a question related to the BufferedInputStream. I'm trying to understand how it works and all that the Java documentation says is "When the BufferedInputStream is created, an internal buffer array is created. As bytes from the stream are read or skipped, the internal buffer is refilled as necessary from the contained input stream, many bytes at a time."
What happens more precisely? After I have read all the values stored in this buffer, does it automatically read new ones from the hard disk? Or when exactly does it cause a call to the underlying system? Can I control its length? And furthermore, if I want to sort the values in the buffer, do I have to put them into an array first?
I don't think you can tell more precisely, unless you download the "native" code for the JVM. It is rather like the difference between calling out individual letters to make a message, and writing those letters on a paper and passing the paper to the recipient.
Joined: Oct 13, 2005
In fact, the actual implementation of that buffer probably varies from one type of JVM to another.