【问题标题】:How to Read contents of a file and write that content to another file in C# WPF如何在 C# WPF 中读取文件的内容并将该内容写入另一个文件
【发布时间】:2018-04-16 17:04:51
【问题描述】:

我正在创建一个 WPF 应用程序,我想在其中读取文件的内容并将其写入另一个文件。

【问题讨论】:

  • SO 不是“提供我使用的代码”的地方
  • 是的,请提供我要使用的代码
  • 我投票决定将此问题作为题外话结束,因为 OP 没有提出任何问题。他只是希望有人为他编码。

标签: filestream streamwriter


【解决方案1】:

你可以在System.IO下使用File...下面是一个例子:

string path1 = "main file path here";
string path2 = "second file path here";
string contents = File.ReadAllText(path1);
File.WriteAllText(path2, contents);

【讨论】:

  • 这很有帮助。谢谢
【解决方案2】:

如果目标已经存在,则要覆盖:

System.IO.File.Copy(sourceFile, targetFile, true);

如果没有:

System.IO.File.Copy(sourceFile, targetFile);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 2011-04-24
    • 2015-07-02
    • 1970-01-01
    • 2021-10-10
    相关资源
    最近更新 更多