File Reading Issue
-
Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK
-
Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK
Post some code.
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK
If you are using the same file object to read the file again, you need to seek the file pointer to beginning of file(BOF), before you read. This is so because you have read to End of File, and when you read again, it tries to read from current position of file pointer. You need to reset the current position to BOF. I dont know what language are u using but it would be something like file.Seek(0); or filestream.SeekBegin(); or something similar. Regards,
Its never over !
-
Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK
If you are reading something other than a text file (say, mp3 or mpeg), there can be multiple EOF in the same file. So it is a better idea to first calculate the size of the file and then read byte by byte. Shibu
-
If you are using the same file object to read the file again, you need to seek the file pointer to beginning of file(BOF), before you read. This is so because you have read to End of File, and when you read again, it tries to read from current position of file pointer. You need to reset the current position to BOF. I dont know what language are u using but it would be something like file.Seek(0); or filestream.SeekBegin(); or something similar. Regards,
Its never over !
shaibee wrote:
If you are using the same file object to read the file again, you need to seek the file pointer to beginning of file(BOF), before you read.
The OP said the file was closed before attempting to open and read from it again.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
Hello Everybody I am opening a file and reading file till end of file and then close that file and again opening the same file but while reading it goes to EOF so i am not able to read that file again. can anyboy tell what could be the Problem and how can i read the file again. Thanks in advance RYK
Use a seek function. If you opened with fopen(...) you use fseek(F,0,SEEK_SET) to rewind it to the beginning. :)
Bram van Kampen