title: Golang: file.Seek and file.WriteAt not working as expected
body: <p>I am trying to make a program which writes at provided offsets in the file, like i can start writing from 20th offset etc.</p>
  
  <p>here is one of sample code i was using as reference</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "io/ioutil"
      "os"
  )
  
  const (
      filename   = "sample.txt"
      start_data = "12345"
  )
  
  func printContents() {
      data, err := ioutil.ReadFile(filename)
      if err != nil {
          panic(err)
      }
      fmt.Println("CONTENTS:", string(data))
  }
  
  func main() {
      err := ioutil.WriteFile(filename, []byte(start_data), 0644)
      if err != nil {
          panic(err)
      }
  
      printContents()
  
      f, err := os.OpenFile(filename, os.O_RDWR, 0644)
      if err != nil {
          panic(err)
      }
      defer f.Close()
  
      if _, err := f.Seek(20, 0); err != nil {
          panic(err)
      }
  
      if _, err := f.WriteAt([]byte("A"), 15); err != nil {
          panic(err)
      }
  
      printContents()
  }
  </code></pre>
  
  <p>But i am always getting the same file content which is beginning from start like</p>
  
  <pre><code>12345A
  </code></pre>
  
  <p>I tried changing the <strong>seek</strong> values to (0,0) and (20,0) and (10,1) randomly which results in same output</p>
  
  <p>Also i tried changing <strong>WriteAt offset</strong> to other offset like 10, 20 but this also resulted in same.</p>
  
  <p>I want to get a solution so that i can write at any specified position in file, suggest me what is wrong in this code.</p>