我有一个很大的文本文件,我想将其拆分成任意数量的较小文件。我需要的行为与 split
终端命令几乎相同,除了我需要文件在它们的最后一行重叠。也就是说,第一个文件的最后一行是第二个文件的第一行,第二个文件的最后一行是第三个文件的第一行,依此类推。
天真的解决方案似乎是从原始文本文件中读取行并在必要时拆分。我想知道是否有一个标准库函数可以让我处理字节而不是字符串,以便更容易地统一拆分文本文件。
在 Go 中是否有类似于 fseek
的东西可以让我这样做?
最佳答案
例如,
func (f *File) Seek(offset int64, whence int) (ret int64, err error)
Seek
sets theoffset
for the nextRead
orWrite
on file tooffset
, interpreted according towhence
: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any.
关于io - 通过不简单地读取行来拆分大文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16048678/