D
DaLoverhino
Hello. I have a FileInputStream, and I try to do the following:
//Save the file's content into a String
while( (readcount = in.read( buffer, 0, buffer.length) != -1) {
// Add buffer to an ever growing string.
}
Now, what I'm noticing is that my buffer.length == 256, and the
tail end of the file is not being loaded into the string.
So what it appears like is happening is that I ask for 256 bytes,
the FileInputStream can only give me say 18 bytes, so it then
returns a -1.
I was expecting in.read(...) to return 18, then on the next call
return -1.
I went on the sun site and found out there's nothing addressing this
specific situation. So does that mean, if I change compilers/machines,
this code could 'do the right thing'?
Does it mean, I have to use available() in order to ensure proper
behavior
across all platforms (that is hardware, compiler, JVM.)? It would seem
against the spirit of Java if it the above code does different things
on
different platforms? I must be missing something here.
thanks for your time.
//Save the file's content into a String
while( (readcount = in.read( buffer, 0, buffer.length) != -1) {
// Add buffer to an ever growing string.
}
Now, what I'm noticing is that my buffer.length == 256, and the
tail end of the file is not being loaded into the string.
So what it appears like is happening is that I ask for 256 bytes,
the FileInputStream can only give me say 18 bytes, so it then
returns a -1.
I was expecting in.read(...) to return 18, then on the next call
return -1.
I went on the sun site and found out there's nothing addressing this
specific situation. So does that mean, if I change compilers/machines,
this code could 'do the right thing'?
Does it mean, I have to use available() in order to ensure proper
behavior
across all platforms (that is hardware, compiler, JVM.)? It would seem
against the spirit of Java if it the above code does different things
on
different platforms? I must be missing something here.
thanks for your time.