C# File Replace(String, String, String)
Description
File Replace(String, String, String)
Replaces the contents
of a specified file with the contents of another file, deleting the original
file, and creating a backup of the replaced file.
Syntax
File.Replace(String, String, String)
has the following syntax.
public static void Replace(
string sourceFileName,//from w w w . jav a2 s. com
string destinationFileName,
string destinationBackupFileName
)
Parameters
File.Replace(String, String, String)
has the following parameters.
sourceFileName
- The name of a file that replaces the file specified by destinationFileName.destinationFileName
- The name of the file being replaced.destinationBackupFileName
- The name of the backup file.
Returns
File.Replace(String, String, String)
method returns
Example
The following code example uses the Replace method to replace a file.
using System;/* w ww . j a v a 2 s .co m*/
using System.IO;
class FileExample
{
public static void Main()
{
string OriginalFile = "test.xml";
string FileToReplace = "test2.xml";
string BackUpOfFileToReplace = "test2.xml.bac";
File.Replace(OriginalFile, FileToReplace, BackUpOfFileToReplace);
}
}