I am reading a .txt file line by line and when the line in the file is "Hello1", I want to Replace that Line with "Hello2" but I dont get that to work.
I think I miss something out here
//Save this emailadress to the RouletteDataBase file
String Path = C:\\File.txt";
System.IO.FileStream sd2 = new System.IO.FileStream(Path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
System.IO.StreamReader ReadThis = new System.IO.StreamReader(sd2);
System.IO.FileStream sd3 = new System.IO.FileStream(Path, System.IO.FileMode.Open, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
System.IO.StreamWriter WriteThis = new System.IO.StreamWriter(sd3);
String GetLine = "";
while (ReadThis.Peek() >= 0) //Read this file
{
GetLine = ReadThis.ReadLine(); //Get the String
if (GetLine != "")
{
if (GetLine == "Hello1")
{
WriteThis.WriteLine("Hello2"); //Replace
}
}
}
sd2.Close(); //close file