lua基础之io

io.close()

closes a file

io.flush()

flushes outstanding data to disk for the default output file

io.input()

opens filename for input in text mode

io.lines()

returns an iterator function for reading a named file line-by-line

io.open()

file = io.open (filename [, mode])

mode

  • r 以只读方式打开文件,该文件必须存在。
  • w 打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失。若文件不存在则建立该文件。
  • a 以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。(EOF符保留)
  • r+ 以可读写方式打开文件,该文件必须存在。
  • w+ 打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。
  • a+ 与a类似,但此文件可读可写
  • b 二进制模式,如果文件是二进制文件,可以加上b
  • +号表示对文件既可以读也可以写

io.output()

opens a file for output

io.popen()

creates a pipe and executes a command

io.read()

reads from the default input file

io.tmpfile()

returns a handle to a temporary file

io.type()

returns type of file handle

io.write()

writes to the default output file

file:close()

closes a file

file:flush()

向文件写入缓冲中的所有数据

file:lines()

returns an iterator function for reading the file line-by-line

file:read()

reads the file according to the specified formats

file:seek(optional whence, optional offset)

设置和获取当前文件位置,成功则返回最终的文件位置(按字节)	
参数 whence 值可以是:
"set": 从文件头开始
"cur": 从当前位置开始[默认]
"end": 从文件尾开始
offset:默认为0
不带参数file:seek()则返回当前位置,file:seek("set")则定位到文件头,file:seek("end")则定位到文件尾并返回文件大小

file:setvbuf()

sets the buffering mode for an output file

file:write()

writes to a file

ok, message = os.remove (filename)

Deletes a file

ok, message = os.rename (oldname, newname)

Renames a file

s = os.tmpname ()

Returns a name for a temporary file
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值