I have an exercise in which they ask me to concatenate the content of the first and second text files through a function, saving the content in the first file, this is what I have done so far, but it does not work for me, ideas?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApp10
{
class Program
{
static void Main(string[] args)
{
string nom1, nom2;
Console.WriteLine("Entra la ruta o nom del primer arxiu");
nom1 = Console.ReadLine();
Console.WriteLine("Entra la ruta o nom del segon arxiu");
nom2 = Console.ReadLine();
inicia(nom1, nom2);
}
static void inicia(string nom1, string nom2)
{
try
{
using (StreamWriter sw = File.AppendText(nom1))
{
using (StreamReader sr = new StreamReader(nom1))
{
string line;
while ((line = sr.ReadLine()) != null)
{
sw.Write(line);
}
using (StreamReader sr2 = new StreamReader(nom2))
{
string line2;
while ((line2 = sr2.ReadLine()) != null)
{
sw.Write(line2);
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Error general");
Console.WriteLine(e.Message);
Environment.Exit(1);
}
Console.ReadKey();
}
}
}