mirror of
https://github.com/MADTeacher/go_basics.git
synced 2025-11-23 21:34:47 +02:00
29 lines
439 B
Go
29 lines
439 B
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"io"
|
||
|
|
"log"
|
||
|
|
"os"
|
||
|
|
)
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
file, err := os.Open("pirates.txt")
|
||
|
|
if err != nil {
|
||
|
|
log.Fatal(err)
|
||
|
|
}
|
||
|
|
defer file.Close()
|
||
|
|
|
||
|
|
tempData := make([]byte, 32)
|
||
|
|
data := []byte{}
|
||
|
|
for {
|
||
|
|
length, err := file.Read(tempData)
|
||
|
|
fmt.Printf("Reading %d byte\n", length)
|
||
|
|
if err == io.EOF { // достигли конца файла?
|
||
|
|
break
|
||
|
|
}
|
||
|
|
data = append(data, tempData...)
|
||
|
|
}
|
||
|
|
fmt.Println(string(data))
|
||
|
|
}
|