Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
17
Task/File-input-output/Go/file-input-output-1.go
Normal file
17
Task/File-input-output/Go/file-input-output-1.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
b, err := ioutil.ReadFile("input.txt")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err = ioutil.WriteFile("output.txt", b, 0666); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
37
Task/File-input-output/Go/file-input-output-2.go
Normal file
37
Task/File-input-output/Go/file-input-output-2.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func CopyFile(out, in string) (err error) {
|
||||
var inf, outf *os.File
|
||||
inf, err = os.Open(in)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
cErr := inf.Close()
|
||||
if err == nil {
|
||||
err = cErr
|
||||
}
|
||||
}()
|
||||
outf, err = os.Create(out)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = io.Copy(outf, inf)
|
||||
cErr := outf.Close()
|
||||
if err == nil {
|
||||
err = cErr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := CopyFile("output.txt", "input.txt"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue