C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Then: After the File.Copy sub returns, we call File.ReadAllText on the original and copied files.
Finally: We display the contents of both files to show that the destination file has the same contents as the original.
Contents, file-a.txt:
How are you today?
VB.NET program that uses File.Copy
Imports System.IO
Module Module1
Sub Main()
' Copy one file to a new location.
File.Copy("file-a.txt", "file-b.txt")
' Display file contents.
Console.WriteLine(File.ReadAllText("file-a.txt"))
Console.WriteLine(File.ReadAllText("file-b.txt"))
End Sub
End Module
Output
How are you today?
How are you today?
Contents 2, file-a.txt:
I am well, thank you.
VB.NET program that overwrites, copies
Imports System.IO
Module Module1
Sub Main()
' Allow the destination to be overwritten.
File.Copy("file-a.txt", "file-b.txt", True)
' Display.
Console.WriteLine(File.ReadAllText("file-a.txt"))
Console.WriteLine(File.ReadAllText("file-b.txt"))
End Sub
End Module
Output
I am well, thank you.
I am well, thank you.
Thus: Optimization guidelines always depend on many factors. A programmer must be able to decide based on program context.