fgetpos available in Go? Want to find File.Position

前端 未结 1 912
迷失自我
迷失自我 2021-01-17 14:59

I have a File and I want to find the file offset/position, what would be fgetpos in stdio. I can\'t seem to find it in http://golang.o

相关标签:
1条回答
  • 2021-01-17 15:55

    You should be able to do a Seek() to 0 bytes from the current position, which returns the resulting position. I'm not 100% sure the result is the absolute position you're after, but I would expect it to be.

    offset, err := f.Seek(0, io.SeekCurrent)
    if err != nil {
        // handle error
    }
    // offset is the current position
    
    0 讨论(0)
提交回复
热议问题