The Replace method replaces the contents of a specified file with the contents of another file. This method deletes the original file and creates a backup of the replaced file.
The following code snippet moves the contents of the original file into the replaced file and also creates a backup of the replaced file and deletes the original file.

string repFile = @"C:\repFile.txt";
string backupFile = @"C:\backupFile.txt.bac";
string fileName = @"C:\fileName.txt";
FileInfo filetoreplace = new FileInfo(fileName);
try
{
		filetoreplace.Replace(repFile, backupFile, false);
}
catch (IOException ex)
{
		Console.WriteLine(ex.Message);
}
vote
Article Rating
Xem thêm  [C#] How to Get and Set File Last Access Time

By admin

Theo dõi
Thông báo khi
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x