Does Writing Files First Erase? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Does Writing Files First Erase?

Part of the course says that: w: Opens file for write only. Erases the contents of the file or creates a new file if it doesn't exist. Does this mean that if you want to write something onto a file, you should use "a" if you want to keep what is already there? Or do you have to first read a file and then write to it what you read plus what you wanted to add?

14th Aug 2020, 9:42 PM
Ac Hybl
1 Answer
+ 4
Yes, using the flag 'a' allows you to append to the file instead of overwriting it without having to read in the content first: https://www.sololearn.com/learn/PHP/1846/
14th Aug 2020, 9:45 PM
Shadow
Shadow - avatar