lua io操作
io 操作
相关函数
io.close(file):关闭文件,file可选,如果没有指定,关闭默认的文件
io.flush():刷新文件
io.input ([file]):设置默认输入文件,io.read从文件中读取内容
io.output ([file]):设置默认的输出文件,io.write向文件中写入内容
io.write (···):向默认文件中写入内容,...为字符串(写入文件的内容)
io.lines ([filename, ···]):以可读模式打开文件,每次返回一行数据
当到文件尾时,将返回nil,但不关闭文件
如不指定filename,则从控制态读取数据
io.read(format):读取文件内容的格式
Reads the file file, according to the given formats, which specify what to read.
For each format, the function returns a string or a number with the characters
read, or fail if it cannot read data with the specified format. (In this latter
case, the function does not read subsequent formats.) When called without
arguments, it uses a default format that reads the next line (see below).
* 根据指定的格式读取文件内容
The available formats are
"n": reads a numeral and returns it as a float or an integer, following the
lexical conventions of Lua. (The numeral may have leading whitespaces and a sign.)
This format always reads the longest input sequence that is a valid prefix for a
numeral; if that prefix does not form a valid numeral (e.g., an empty string, "0x",
or "3.4e-"