using System; using System.IO; class CopyFile { static void Main() { string sourceFile = @"C:\Users\Public\TestFolder\test.txt"; string destinationFile = @"C:\Users\Public\TestFolder\test_copy.txt"; // Create a FileStream for the source file using (FileStream input = new FileStream(sourceFile, FileMode.Open)) { // Create a FileStream for the destination file using (FileStream output = new FileStream(destinationFile, FileMode.Create)) { // Copy the input file to the output file input.CopyTo(output); } } } }
using System; using System.IO; class CopyFile { static void Main() { string sourceFile = @"C:\Users\Public\TestFolder\image.jpg"; string destinationFile = @"C:\Users\Public\TestFolder\image_copy.jpg"; // Create a FileStream for the source file using (FileStream input = new FileStream(sourceFile, FileMode.Open)) { // Create a FileStream for the destination file using (FileStream output = new FileStream(destinationFile, FileMode.Create)) { // Copy the input file to the output file input.CopyTo(output); } } } }In this example, we are copying an image file named "image.jpg" to another file named "image_copy.jpg". We are using the C# FileStream CopyTo method to accomplish this. The C# FileStream CopyTo method is part of the System.IO library in C#.