io - 通过不简单地读取行来拆分大文本文件

标签 io go fseek

我有一个很大的文本文件,我想将其拆分成任意数量的较小文件。我需要的行为与 split 终端命令几乎相同,除了我需要文件在它们的最后一行重叠。也就是说,第一个文件的最后一行是第二个文件的第一行,第二个文件的最后一行是第三个文件的第一行,依此类推。

天真的解决方案似乎是从原始文本文件中读取行并在必要时拆分。我想知道是否有一个标准库函数可以让我处理字节而不是字符串,以便更容易地统一拆分文本文件。

在 Go 中是否有类似于 fseek 的东西可以让我这样做?

最佳答案

例如,

Package os

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (ret int64, err error)

Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 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/

相关文章:

c++ - 如何计算文本文件中特定单词的出现次数

go - 加密聊天中的"runtime error: slice bounds out of range"

c - 电脑是怎么算的?

http - 从某些函数调用时,Haskell System.Timeout.timeout崩溃

C - 数组、排序和修改

firebase - 如何验证 Google Firebase admin SDK 凭据是否正确

go - 从 Golang 执行 web2exe 给我 'exit status 2'

c - 逐行读取数组中的文件

c++ - 快速查找文件中的位置

Java I/O 到 .txt 文件