如何从Julia的开头开始读取文件x字节?

如何从Julia的开头开始读取文件x字节?

问题描述:

我需要从文件中读取记录,每个记录长9个字节.我需要知道如何从文件的不同位置开始读取

I need to read records from a file, each being 9 bytes long. I need to know how to start reading at different points in the file

您似乎正在寻找seek函数:

help?> seek
search: seek seekend seekstart ParseError setenv select select! selectperm

  seek(s, pos)

  Seek a stream to the given position.

尤其是您可能想要

open(filename) do f
    seek(f, n)  # seek past nth byte
    read(f, m)  # read m bytes
end

还有skip功能可能会有用

help?> skip
search: skip skipchars

  skip(s, offset)

  Seek a stream relative to the current position.