且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从两个.txt文件中复制文本并使用C#将其粘贴到第三个文件中

更新时间:2023-01-31 12:36:39

您好,试试这个代码,然后参考项目中的System.IO命名空间。

  string  FirstFileContents = File.ReadAllText( 这里的第一个文件路径); 
string SecondFileContents = File.ReadAllText( 你的第二个文件路径);
StringBuilder ThirdFileContents = new StringBuilder();
ThirdFileContents.Append(ThirdFileContents.ToString());

File.WriteAllText( 这里的第三个文件路径,ThirdFileContents) ;


你在这里缺乏基本的想法。

首先你需要从两个文件中读取文本,存储它在某个对象/集合中(根据您的喜好)然后将其写入一些不同的文件。

(确保您具有访问该文件的适当权限。)



看看这个&你很高兴,

从文件中读取 [ ^ ]

写入文件 [ ^ ]



-KR

i want to copy text from two .txt file and then want to paste in the third .txt file.

Hi, try this code, and refer System.IO namespace in your project.
string FirstFileContents = File.ReadAllText("your first file path here");
string SecondFileContents = File.ReadAllText("your second file path here");
StringBuilder ThirdFileContents = new StringBuilder();
ThirdFileContents.Append(ThirdFileContents.ToString());

File.WriteAllText("your third file path here", ThirdFileContents);


You're lacking the basic idea here.
First you need to read the text from both the files, store it in some object/collection (whichever you prefer) and then write it to some different file.
(Make sure that you have appropriate permissions to access the file.)

Look at this & you're good to go then,
Read from a File[^]
Write to a File[^]

-KR