Im trying to write a class to replace strings in a text file but for some reason StreamWriter will not work in my class. Its not throwing any exceptions or anything its just not writing to the text file. Also I used to have a destructor in my class but it was throwing an exception when I tried to close or dispose outFile.
Code:
class TextReplacer
{
private StreamReader inFile;
private StreamWriter outFile;
public TextReplacer(StreamReader _in, StreamWriter _out)
{
inFile = _in;
outFile = _out;
outFile.WriteLine("TESTING!!!"); // DOES NOT WORK
}
public void Repace(string find, string replace)
{
string line = inFile.ReadLine();
if (line != null)
{
line = line.Replace(find, replace);
Console.WriteLine(line);
outFile.WriteLine(line); // DOES NOT WORK
Repace(find, replace);
}
return;
}
}
Comment