您需要
f.Seek跳过第一个字节并进行常规读取,请参见示例:
package mainimport ( "fmt" "io" "io/ioutil" "os")func main() { f, err := os.Open(os.Args[1]) // open file from argument if err != nil { fmt.Println(err) return } var skipBytes int64 = 5 // how many bytes to skip _, err = f.Seek(skipBytes, io.SeekStart) // skipping first bytes if err != nil { fmt.Println(err) return } buffer := make([]byte, 1024) // allocating buffer to read for { n, err := f.Read(buffer) // reading fmt.Print(string(buffer[:n])) // writing to console if err != nil { fmt.Printf("Err: %vn", err) return } }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)