31 lines
489 B
Go
31 lines
489 B
Go
|
package tool
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func CopyFile(src string, dst string) (err error) {
|
||
|
// Open the source file
|
||
|
sourceFile, err := os.Open(src)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer sourceFile.Close()
|
||
|
|
||
|
// Create the destination file
|
||
|
destinationFile, err := os.Create(dst)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer destinationFile.Close()
|
||
|
|
||
|
// Copy the contents from source to destination
|
||
|
_, err = io.Copy(destinationFile, sourceFile)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|