Maison  >  Article  >  développement back-end  >  Programme C# pour copier des fichiers existants

Programme C# pour copier des fichiers existants

WBOY
WBOYavant
2023-09-08 18:21:161890parcourir

C# 程序复制现有文件

Utilisez la méthode File.Copy pour copier un fichier existant.

Ajoutez le chemin du fichier que vous souhaitez copier.

String myPath = @"D:\one.txt";

Maintenant, copiez le fichier ci-dessus dans le fichier suivant −

String myPath = @"D:\one.txt";

Utilisez la méthode File.Copy, en spécifiant les fichiers source et de destination.

File.Copy(myPath,newpath);

Exemple

using System;
using System.IO;
public class Program {
   public static void Main() {
      String myPath = @"D:\one.txt";
      // the file will get copied here
      String newpath = @"D:\two.txt";
      // copying file
      File.Copy(myPath,newpath);
   }
}

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer