["$ file..G$ ","|File.Copy$File.Copy parameters$demonstrates File.Copy exceptions|","HUGVXGGusing System;Gusing System.IO;GGclass ProgramG{GHstatic void Main()GH{XUXGHH// Copy one file to a nonexistent locationGHHXFile.CopyX(XVfile-a.txtVX, XVfile-new.txtVX);XGGHH// Display the contents of both filesGHHXConsole.WriteLine(File.ReadAllText(XVfile-a.txtVX));GHHConsole.WriteLine(File.ReadAllText(XVfile-new.txtVX));GH}G}GGXGGContents of File A.GContents of File A.XUXGHH// Write initial contents of File B.GHHXConsole.WriteLine(File.ReadAllText(XVfile-b.txtVX));XGHH// VFile B contents.VGGHH// COPY:GHH// Copy one file to a location where there is a file.GHHXFile.CopyX(XVfile-a.txtVX, XVfile-b.txtVX, true);X // overwrite = trueGGHH// Display the contents of both filesGHHXConsole.WriteLine(File.ReadAllText(XVfile-a.txtVX));GHHConsole.WriteLine(File.ReadAllText(XVfile-b.txtVX));GH}G}GGXGGVContents of File A.VGVContents of File A.VXUXGHH// Copying a file that doesn't exist:GHHXtryGHH{GHHHXFile.CopyX(XVfile-missing.txtVX, XVfile-new.txtVX);GHH}GHHcatch (Exception ex)GHH{GHHHConsole.WriteLine(ex);XGHHH// System.IO.FileNotFoundException: Could not find file 'file-missing.txt'.GHHX}XGGHH// Copying to a file without overwriteGHHXtryGHH{GHHHXFile.CopyX(XVfile-a.txtVX, XVfile-b.txtVX);GHH}GHHcatch (Exception ex)GHH{GHHHConsole.WriteLine(ex);XGHHH// System.IO.IOException: The file 'file-b.txt' already exists.GHHX}GH}G}X","A*rCEfBD*]CC| G7868}* 64G7868}(XBB 986986`BB(BCCE+BCE.","File.Copy"," copies a file from one location to another. It leaves both copies on the disk. It is part of the System.IO namespace. We break down three common uses of File.Copy. We warn of potential errors.","Example."," Here we want to copy one file to a new location, one where no file exists. This is straightforward and you will see that both files in the example, file-a.txt and file-new.txt, have the same contents. ","Next: ","This program takes a file that exists, file-a.txt, and copies it to file-new.txt. Both files contain the same string.","It displays the contents of both files, using Console.WriteLine and File.ReadAllText, to prove equality.","Example 2."," We find that File.Copy will cause an exception if you use it when the target destination already has a file there. To solve this problem, you must specify the third parameter of File.Copy to be true. ","First the example"," displays the contents of file-b.txt. Then it calls File.Copy and copies file-a.txt to file-b.txt. No exception is thrown here. It finally displays the contents of the two files, which are now equal.","Example 3."," File.Copy will throw FileNotFoundException and IOException if there are certain problems. It will also throw other exceptions that I do not show here. You will find them annoying enough without my help. ","FileNotFoundException ","filenotfoundexception","IOException ","io","The program"," has two try-catch blocks. The first one protects the program from a call to File.Copy that tries to copy a missing file. It demonstrates that the FileNotFoundException is thrown. ","Try ","try","Catch ","catch","Next,"," the second try-catch block demonstrates that the IOException is thrown when you try to copy to a file that exists, but don't specify overwrite. To specify overwrite, use true as the third parameter. ","True, False ","true","Caution: ","File IO will occasionally throw exceptions. It is one of the best uses for exception-handling.","You should wrap your File.Copy, as well as other methods such as File.ReadAllText, inside a try-catch block.","File.ReadAllText ","file-readalltext","Discussion."," The File.Replace combine File.Copy with a deletion of the file. You can duplicate its functionality with File.Copy and then File.Delete. File.Move does a file system rename instead of copying any data. ","File.Move ","file-move","More information on exceptions caused by File.Copy and other methods in System.IO is available.","Exception ","exception","Summary."," Here we saw two useful ways to use File.Copy in the C# language, and saw examples of two ways it can throw exceptions. It is important that you handle errors when using File.Copy, or it may bring down your program."]

%iVBORw0KG;)NSUhEUg?AK)AxCAM?ABqK1L5)MFBMVEX:/+zzvd8rvO/1fj1+P4xiu5tpfFbnfDg6/xIk++ZvvWLtvSmxvbV5Pvr8v3K3PnaFXRJ)1ElEQVR4Xu3W7QbEMBBG4Xcm3/3a+7/bVZRlqEI5Vs7vhIcwE+3lQbrP4/kHN2LNfbW06zcAMDTWlFnA2LDMAsbGBwaMJTqwJDqw7HRgpQNLogOdDiwHHZjowEXqflXj7r56H2hmW43AevttMIVeA+qsRyILqE4HKrxyhwG3sO1gQPt34AQ6HJgHfMxsBQ081uBrGKC7txJbAcDbjA7scOAQHGhw4DjgQBMbWMUGt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