lua 文件操作
文件操作
相关函数:相比于io操作,file可同时操作多个文件
file:close ():关闭文件
file:flush ():刷新文件,将写入内容刷新到文件中
file:write (···):向文件中写入内容
file.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-") or it is too long (more than 200 characters), it is discarded and the
format returns fail.
"a": reads the whole file, starting at the current position. On end of file, it
returns the empty string; this format never fails.
"l": reads the next line skipping the end of line, returning fail on end of
file. This is the def