this repo has no description

:sparkles: (Go) file seek

Changed files
+40
Go
input
+40
Go/input/file-seek.go
··· 1 + package main 2 + 3 + import ( 4 + "fmt" 5 + "os" 6 + ) 7 + 8 + func main() { 9 + tmp := os.TempDir() 10 + file, err := os.Create(tmp + "/myfile") 11 + if err != nil { 12 + panic(err) 13 + } 14 + defer file.Close() 15 + 16 + msg := "Save the world with Go!" 17 + 18 + _, err = file.WriteString(msg) 19 + if err != nil { 20 + panic(err) 21 + } 22 + 23 + positions := []int{4, 10, 20} 24 + for _, i := range positions { 25 + _, err := file.Seek(int64(i), 0) 26 + if err != nil { 27 + panic(err) 28 + } 29 + file.Write([]byte("X")) 30 + } 31 + 32 + file.Seek(0, 0) 33 + 34 + result := make([]byte, len(msg)) 35 + if _, err := file.Read(result); err != nil { 36 + panic(err) 37 + } 38 + 39 + fmt.Printf("%s\n", result) 40 + }