file, err := os.Open("myfile.txt") if err != nil { log.Fatal(err) } defer file.Close() data := make([]byte, 16) n, err := file.ReadAt(data, 10) if err != nil { log.Fatal(err) } fmt.Printf("Read %d bytes: %s\n", n, string(data[:n]))
file, err := os.Open("myfile.txt") if err != nil { log.Fatal(err) } defer file.Close() data := make([]byte, 8) n, err := file.ReadAt(data, 0) if err != nil { log.Fatal(err) } fmt.Printf("Read %d bytes: %s\n", n, string(data[:n]))In this example, we read 8 bytes from the beginning of the file named `myfile.txt`. The `os` package is a standard library package in Go that provides a platform-independent interface for operating system functionality such as file I/O operations.