File.position read/write property



The File.position property get or set the current file position, as a number. The file must have been opened before using this property.

File position always starts at 1. File position interpretation depends on the file encoding.
  • In "binary" encoding : the position is expressed in bytes.
  • In "utf8" or "unicode" encoding : the position is expressed in characters (and you don't have to care about BOM).

Example

local file = sys.File("unicode.txt") file:open("write", "unicode") file:write("Hello World !") file:close() file:open("read") file.position = 8 -- read one character starting at position 8 : outputs "o" print("["..file:read(1).."]")