Unimatrix_001
asked on
Reading more than possible from a file.
What happens in the following:
fileInput.read(memoryBlock , 512);
fileInput.close();
But from the current read position to the end of the file is only 511 bytes? Will it read 511 bytes and silently ignore the 512 byte, or should a specific check be done to ensure 512 bytes are there, and handle accordingly?
Thanks,
Uni
fileInput.read(memoryBlock
fileInput.close();
But from the current read position to the end of the file is only 511 bytes? Will it read 511 bytes and silently ignore the 512 byte, or should a specific check be done to ensure 512 bytes are there, and handle accordingly?
Thanks,
Uni
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Lets imagine that 512 is only buffer size so the buffer can containt 512 or less symbols.
ASKER
Infinity: Thanks very much! As a side question, what is the point in having both an eofbit and a failbit if one also sets the other?
Alex: Perhaps you forgot to put an answer with that?
Uni.
Alex: Perhaps you forgot to put an answer with that?
Uni.
>> what is the point in having both an eofbit and a failbit if one also sets the other?
when the eofbit is set - it doesn't necessarily mean that the failbit is set too - in this specific case it's true though :
eofbit is set because the end of the file is reached
failbit is set because you tried to read further than the end of the file
There's a slight difference in meaning ...
when the eofbit is set - it doesn't necessarily mean that the failbit is set too - in this specific case it's true though :
eofbit is set because the end of the file is reached
failbit is set because you tried to read further than the end of the file
There's a slight difference in meaning ...
ASKER
Ah I understand now. :)