Skip to content

Instantly share code, notes, and snippets.

@yakuter
Created February 15, 2024 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakuter/83cab3c9dc5650f3137675cd83120ad7 to your computer and use it in GitHub Desktop.
Save yakuter/83cab3c9dc5650f3137675cd83120ad7 to your computer and use it in GitHub Desktop.
Copy and Movement 4
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