• lua基础之io


    io.close()

    closes a file
    
    • 1

    io.flush()

    flushes outstanding data to disk for the default output file
    
    • 1

    io.input()

    opens filename for input in text mode
    
    • 1

    io.lines()

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

    io.open()

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

    mode

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

    io.output()

    opens a file for output
    
    • 1

    io.popen()

    creates a pipe and executes a command
    
    • 1

    io.read()

    reads from the default input file
    
    • 1

    io.tmpfile()

    returns a handle to a temporary file
    
    • 1

    io.type()

    returns type of file handle
    
    • 1

    io.write()

    writes to the default output file
    
    • 1

    file:close()

    closes a file
    
    • 1

    file:flush()

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

    file:lines()

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

    file:read()

    reads the file according to the specified formats
    
    • 1

    file:seek(optional whence, optional offset)

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

    file:setvbuf()

    sets the buffering mode for an output file
    
    • 1

    file:write()

    writes to a file
    
    • 1

    ok, message = os.remove (filename)

    Deletes a file
    
    • 1

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

    Renames a file
    
    • 1

    s = os.tmpname ()

    Returns a name for a temporary file
    
    • 1
  • 相关阅读:
    白嫖一个月的ES,完成了与MySQL的联动
    vue 图片转base64格式的方法
    hive里因为列名用了关键字导致建表失败
    DevOps系列文章之 Docker-compose
    如何通过 Chainlink Price Feeds获得加密资产的历史价格
    使用MySQL和SQL Server生成最近七周和最近七个月的日期数据
    在master分支进行代码回滚
    M10C车载SD卡录像机产品外观结构图
    vite(setup语法糖)+ts+vant+axios入门教程
    盘点60个Python各行各业管理系统源码Python爱好者不容错过
  • 原文地址:https://blog.csdn.net/a_codecat/article/details/127951306