File:read([length]) method

Reads data from the file.

Parameters

length

An optional number indicating the number of characters (or bytes in binary encoding) to read.
When no value is provided, the method read all data from the current position until the end of file is reached.

Return value

Returns the data as a string (for utf8 and unicode encoding) or as a Buffer (for binary encoding).

Example

local console = require "console" console.write("Do you want to quit ? (y/n) ") -- read one character from console.stdin standard File local c = console.stdin:read(1) if c == "y" then print("Bye !") else print("Let's continue...") end