1.Copy
1
2
3
4
|
string
sourceFile =
@"c:\temp\New Text Document.txt"
;
string
destinationFile =
@"c:\temp\test.txt"
;
bool
isrewrite=
true
;
// true=覆盖已存在的同名文件,false则反之
System.IO.File.Copy(sourcePath, targetPath, isrewrite);
|
2.CopyTo
1
2
3
4
5
6
7
8
|
string
sourceFile =
@"c:\temp\New Text Document.txt"
;
string
destinationFile =
@"c:\temp\test.txt"
;
FileInfo file =
new
FileInfo(sourceFile);
if
(file.Exists)
{
// true is overwrite
file.CopyTo(destinationFile,
true
);
}
|