In some cases, you need to read from or write to a particular location in a file, such as an indexed file. The recipe will show you how to use the position seeking in the context of flat file operations.
Seeking a position within a file
How to do it...
- Open the console and create the folder chapter05/recipe06.
- Navigate to the directory.
- Create the file flatfile.txt with the following content:
123.Jun.......Wong......
12..Novak.....Jurgen....
10..Thomas....Sohlich...
- Create the fileseek.go file with the following content:
package main
import (
"errors"
"fmt"
"os"
)
const lineLegth = 25
func main() {
...