开发者

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

开发者 https://www.devze.com 2023-04-03 09:49 出处:网络
i have 2 files that contain text, file1 and file2 i need to add the content of file2 to file1 fi开发者_如何学JAVAle1

i have 2 files that contain text, file1 and file2

i need to add the content of file2 to file1

fi开发者_如何学JAVAle1
=====
111
222
333

file2
=====
444
555
666

after the add file1 will look like this:

111
222
333
444
555
666


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


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消