on the below code I read a file line by line and try to save the read lines in another file. If I display the read lines in the console, it shows the correct content of the read file (test1.txt). But when I check the content of saved file (test2.txt) it is empty. I tried many other codes and the result is the same. I do not know what is wrong. Can anyone help me? Thanks. test1.txt content = (four lines) 1 2 3 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace texto
{
class Program
{
static void Main(string[] args)
{
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file = new
System.IO.StreamReader(@"c:\Dados\test1.txt");
System.IO.StreamWriter file1 = new
System.IO.StreamWriter(@"c:\Dados\test2.txt");
while ((line = file.ReadLine()) != null)
{
counter++;
//string file3 = line.Substring(0, (23));
file1.WriteLine(line + " " + counter);
}
file.Close();
System.Console.WriteLine("There were {0} lines.", counter);
// Suspend the screen.
System.Console.ReadLine();
}
}
}