如何在C#中复制文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-01 09:04:03 来源:igfitidea点击:
How to copy a file in C#
提问by Daren Thomas
I want to copy a file from A to B in C#. How do I do that?
我想在 C# 中将文件从 A 复制到 B。我怎么做?
回答by Jedi Master Spooky
System.IO.File.Copy
系统.IO.文件.复制
回答by Eric Z Beard
Use the FileInfo class.
使用 FileInfo 类。
FileInfo fi = new FileInfo("a.txt");
fi.CopyTo("b.txt");
回答by Corey
Without any error handling code:
没有任何错误处理代码:
File.Copy(path, path2);
回答by Stan van de Bovenkamp
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);