fgetpos在Go语言中可用吗?想要找到文件,位置

xvw2m8pv  于 2022-12-07  发布在  Go
关注(0)|答案(2)|浏览(89)

我有一个File,我想找到文件的偏移/位置,stdio中的fgetpos是多少。我似乎在http://golang.org/pkg/io/中找不到它。我必须自己计算吗?还是有内置方法?

4nkexdtk

4nkexdtk1#

你应该能够从当前位置执行Seek()到0字节的操作,返回结果位置。我不能100%确定结果是你要找的绝对位置,但我希望它是。

offset, err := f.Seek(0, io.SeekCurrent)
if err != nil {
    // handle error
}
// offset is the current position
rjzwgtxy

rjzwgtxy2#

这应该是可行:
当前位置,错误:=文件。Seek(0,1)
我从这里读到:
https://cihanozhan.medium.com/file-operations-in-golang-292825c9fb3d

相关问题