I have been looking at writing a string into a file and then read it line by line, but I always get the error IOException: Sharing violation on path C:...\level1.txt. I looked on the internet and they said I should use the same stream to write and read but it didn't work,so I tried to make a different stream for each one and it didn't work either.
FileStream F = new FileStream("level1.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(F);
sw.Write(Gui.codeText.Replace("\n", "\r\n"));
F.Close();
FileStream F2 = new FileStream("level1.txt", FileMode.Open, FileAccess.Read);
StreamReader file = new StreamReader(F2);
while ((line = file.ReadLine()) != null)
{ ....}