File closing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

File closing

What is the effect on code when we don't close the file?

8th Jul 2020, 6:25 AM
Priya Deshmukh
3 Answers
8th Jul 2020, 6:27 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 5
A lot of information about this issue. So from my experience, keeping a file open, is a high risk when the program crashes before a file will be closed. I have done a small test program that is doing: - creating a file, writing to this file, closing this file - opening the file, reading the created file and display the file content, closing this file - opening the created file again, write information to the file, and create a crash -> The result is, that the COMPLETE content of the file is gone. You can try the code in the attached file, but it does not work in playground, as file we create there are only temporary during runtime of the program. https://code.sololearn.com/c1RcN9OkVDIC/?ref=app
8th Jul 2020, 10:30 AM
Lothar
Lothar - avatar