我有一个File,我想找到文件的偏移/位置,stdio中的fgetpos是多少。我似乎在http://golang.org/pkg/io/中找不到它。我必须自己计算吗?还是有内置方法?
File
stdio
fgetpos
4nkexdtk1#
你应该能够从当前位置执行Seek()到0字节的操作,返回结果位置。我不能100%确定结果是你要找的绝对位置,但我希望它是。
Seek()
offset, err := f.Seek(0, io.SeekCurrent) if err != nil { // handle error } // offset is the current position
rjzwgtxy2#
这应该是可行:当前位置,错误:=文件。Seek(0,1)我从这里读到:https://cihanozhan.medium.com/file-operations-in-golang-292825c9fb3d
2条答案
按热度按时间4nkexdtk1#
你应该能够从当前位置执行
Seek()
到0字节的操作,返回结果位置。我不能100%确定结果是你要找的绝对位置,但我希望它是。rjzwgtxy2#
这应该是可行:
当前位置,错误:=文件。Seek(0,1)
我从这里读到:
https://cihanozhan.medium.com/file-operations-in-golang-292825c9fb3d