Gali
Gali

Reputation: 14963

how to add text File2 content to the end of text file1

i have 2 files that contain text, file1 and file2

i need to add the content of file2 to file1

file1
=====
111
222
333

file2
=====
444
555
666

after the add file1 will look like this:

111
222
333
444
555
666

Upvotes: 1

Views: 52

Answers (2)

user929948
user929948

Reputation:

Using below code :

StreamReader sr = new StreamReader(filePath2);
string fileString = sr.ReadToEnd();
    sr.Close();
StreamWriter sw = new StreamWriter(filePath1,true);
sw.WriteLine(fileString);
    sw.Close();

Upvotes: 0

Scott
Scott

Reputation: 999

File.AppendAllText("file1.txt", Environment.NewLine + File.ReadAllText("file2.txt"));

Upvotes: 3

Related Questions