How to write contents of one file to another file?

后端 未结 8 1458
遇见更好的自我
遇见更好的自我 2020-12-09 10:46

I need to write contents of a file to another file using File.OpenRead and File.OpenWrite methods. I am unable to figure out how to do it.

How can i modify the follo

8条回答
  •  离开以前
    2020-12-09 11:24

    You should be using File.Copy unless you want to append to the second file.

    If you want to append you can still use the File class.

    string content = File.ReadAllText("C:\\file1.txt");
    File.AppendAllText("D:\\file2.txt",content);
    

提交回复
热议问题