Golang os.File.ReadAt() function example
package os
Golang os.File.ReadAt() function usage example
package main
import (
"fmt"
"io"
"os"
)
func main() {
file, err := os.Open("data.txt")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
// create a buffer to keep chunks that are ReadAt
buffer := make([]byte, 1024)
// read at
n, err := file.ReadAt(buffer, 10)
if err != nil && err != io.EOF {
panic(err)
}
// out the buffer content
fmt.Println(string(buffer[:n]))
}
Reference :
Advertisement
Something interesting
Tutorials
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+9.9k Golang : Check if user agent is a robot or crawler example
+4.6k Javascript : Detect when console is activated and do something about it
+9.6k Javascript : Read/parse JSON data from HTTP response
+26.9k Golang : Force your program to run with root permissions
+48.5k Golang : Upload file from web browser to server
+7.3k Golang : alternative to os.Exit() function
+14.3k Golang : Get uploaded file name or access uploaded files
+9.4k Golang : Apply Histogram Equalization to color images
+7.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+12.2k Golang : calculate elapsed run time
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?