Check out example codes for "how clear all line in text file and write new string in c#". It will help you in understanding the concepts better.

Code Example 1

if (File.Exists(ModuleListPath))
            {
                File.WriteAllText(ModuleListPath, String.Empty);
            }

            foreach (var item in list)
            {
                using (StreamWriter stream = new StreamWriter(ModuleListPath,true))
                {
                    try
                    {
                        stream.WriteLine(item);
                        
                    }
                    catch
                    {
                        trow;
                    }
                }
            }

Learn ReactJs, React Native from akashmittal.com