How to copy a file in C#

前端 未结 5 1277
闹比i
闹比i 2020-12-17 21:26

I want to copy a file from A to B in C#. How do I do that?

相关标签:
5条回答
  • 2020-12-17 21:34

    The File.Copy method:

    MSDN Link

    0 讨论(0)
  • 2020-12-17 21:42

    This should work!

    using System.IO;
    
    ...
    
    var path = //your current filePath
    var outputPath = //the directory where you want your (.txt) file
    
    
    File.Copy(path,outputPath);
    
    0 讨论(0)
  • 2020-12-17 21:44

    Without any error handling code:

    File.Copy(path, path2);
    
    0 讨论(0)
  • 2020-12-17 21:45

    System.IO.File.Copy

    0 讨论(0)
  • 2020-12-17 21:54

    Use the FileInfo class.

    FileInfo fi = new FileInfo("a.txt");
    fi.CopyTo("b.txt");
    
    0 讨论(0)
提交回复
热议问题