Created
February 15, 2024 08:24
-
-
Save yakuter/83cab3c9dc5650f3137675cd83120ad7 to your computer and use it in GitHub Desktop.
Copy and Movement 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"os" | |
) | |
func main() { | |
sourcePath := "source.txt" | |
destinationPath := "destination.txt" | |
sourceFile, err := os.Open(sourcePath) | |
if err != nil { | |
fmt.Println("Failed to open source file:", err) | |
return | |
} | |
defer sourceFile.Close() | |
destinationFile, err := os.Create(destinationPath) | |
if err != nil { | |
fmt.Println("Failed to create destination file:", err) | |
return | |
} | |
defer destinationFile.Close() | |
_, err = io.Copy(destinationFile, sourceFile) | |
if err != nil { | |
fmt.Println("Failed to copy:", err) | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment