I'm creating a C# code that is required to read a text file line by line and then copy each line onto a new text file. I was able to figure out how to read line by line, but I'm having trouble copying line by line to the new text file I created.
This is what I am using to read my original text file line by line:
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(@"c:\AnswerFile.txt");
while ((line = file.ReadLine()) != null)
{
System.Console.WriteLine(line);
counter++;
}
file.Close();
System.Console.WriteLine("There were {0} lines.", counter);
// Suspend the screen.
System.Console.ReadLine();
Any help is appreciated! Thank you
EDIT: I did not forget to write the code that copies the text onto another text file. That is the part I am having trouble with. I tried using streamwriter while specifying the directory of the file I want the text to go to, but something wasn't right. I want to create a code that literally reads line by line from one text file and copies line by line (as it reads from the initial file) to the new text file. I hope that clarifies my question.
EDIT2: Figured it out guys. Thank you for all the help! I had to call my company's security department to grant me access to write in the c drive.