C# File Copy(String, String)

Description

File Copy(String, String) Copies an existing file to a new file. Overwriting a file of the same name is not allowed.

Syntax

File.Copy(String, String) has the following syntax.


public static void Copy(
  string sourceFileName,
  string destFileName
)

Parameters

File.Copy(String, String) has the following parameters.

  • sourceFileName - The file to copy.
  • destFileName - The name of the destination file. This cannot be a directory or an existing file.

Returns

File.Copy(String, String) method returns

Example

The following example copies files.


/*from w  ww  . j  a  va  2  s.  c  o m*/

using System;
using System.IO;
public class MainClass{
  public static void Main(String[] argv){  
    File.Copy("a.txt", "b.txt");
  }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter