Issue
How can we read only a selected portion of a file?
Like this: Read(file, start, length)
Solution
You can use :file.position/2
and :file.read/2
.
With:
$ seq 10 > 10.txt
and code:
{:ok, file} = :file.open("10.txt", [:read, :binary])
:file.position(file, 5)
IO.inspect :file.read(file, 10)
The output is:
{:ok, "\n4\n5\n6\n7\n8"}
That's 10 bytes starting at the 6th byte.
Answered By - Dogbert Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.