Re: [go-nuts] how to seek in file using go

2017-01-18 Thread Ayan George
On 01/19/2017 02:00 AM, hui zhang wrote: > so the file seek does not work in bufio.Read ? > It looks like this has been answered before: https://groups.google.com/forum/#!topic/golang-nuts/mOvX0bmJoeI You could also create another bufio.Reader after you seek like: rd := bufio.NewReade

Re: [go-nuts] how to seek in file using go

2017-01-18 Thread Konstantin Khomoutov
On Wed, 18 Jan 2017 23:00:33 -0800 (PST) hui zhang wrote: > so the file seek does not work in bufio.Read ? You might need to use the Reset() method of your bufio.Reader value before you reposition the pointer in the underlying opened file. Please see `go doc bufio.Reader.Reset`. But this pose

Re: [go-nuts] how to seek in file using go

2017-01-18 Thread Konstantin Khomoutov
On Wed, 18 Jan 2017 22:54:31 -0800 (PST) hui zhang wrote: [...] > > 2. So we now read the docs on os.File: > > > > $ go doc os.File > > > >...and see all of its methods there, inclusing Seek(). > > > > 3. So we read the docs on it: > > > > $ go doc os.File.Seek > > > thanks all

Re: [go-nuts] how to seek in file using go

2017-01-18 Thread hui zhang
so the file seek does not work in bufio.Read ? 在 2017年1月19日星期四 UTC+8下午2:59:39,hui zhang写道: > > fi.Seek(0, os.SEEK_SET )? > > > I set this in the code and I expected to print 3.13 twice , but this code > print 3.13 3.14 > why? > > package main > > import ( >_ "bytes" >"fmt" >

Re: [go-nuts] how to seek in file using go

2017-01-18 Thread hui zhang
fi.Seek(0, os.SEEK_SET )? I set this in the code and I expected to print 3.13 twice , but this code print 3.13 3.14 why? package main import ( _ "bytes" "fmt" _ "math" "bufio" "encoding/binary" "os" ) func main() { var pi float64 //b := []byte{0x18, 0x2d, 0

Re: [go-nuts] how to seek in file using go

2017-01-18 Thread hui zhang
thanks all, I use ide go to definition, it go to the file_unix.go in this file seek is a private method. So I am confused 在 2017年1月19日星期四 UTC+8下午2:45:16,Konstantin Khomoutov写道: > > On Wed, 18 Jan 2017 22:22:48 -0800 (PST) > hui zhang > wrote: > > [...] > >fi, err := os.Open("./output.

Re: [go-nuts] how to seek in file using go

2017-01-18 Thread Konstantin Khomoutov
On Wed, 18 Jan 2017 22:22:48 -0800 (PST) hui zhang wrote: [...] >fi, err := os.Open("./output.bin") [...] >fi.seek()? The usual drill is: 1. Get the documentation on os.Open(): $ go doc os.Open Notice what it returns in its 1st return value has the type *File. Sinc

Re: [go-nuts] how to seek in file using go

2017-01-18 Thread Ayan George
On 01/19/2017 01:22 AM, hui zhang wrote: > I am using encoding/binary to read/write (struct)data to/from file. > Some times , I need to seek in the file while reading . > how to do this in go. > Check the code below [snip!] > > > fi, err := os.Open("./output.bin") >if err != nil { > pa

[go-nuts] how to seek in file using go

2017-01-18 Thread hui zhang
I am using encoding/binary to read/write (struct)data to/from file. Some times , I need to seek in the file while reading . how to do this in go. Check the code below package main import ( _ "bytes" "fmt" _ "math" "bufio" "encoding/binary" "os" ) func main() { var pi flo