跳到主要内容

读取单行文本 (LCC.web_file.get_line)

声明

line, err = LCC.web_file.get_line(path, line_number, timeout?)

参数

  • path
    字符串型,目标文件路径
  • line_number
    数值型,要读取的行号;正数从 1 起算,负数从末尾倒数(-1 为最后一行),0 表示末行之后
  • timeout
    数值型,可选;请求超时时间(秒),默认 60

返回值

  • line
    字符串型或 nil,指定行的内容;未读到目标行时返回空字符串,失败时为 nil
  • err
    字符串型或 nil,仅在失败时返回错误描述

说明

读取指定行号的单行内容。
正数从 1 起算,负数从末尾倒数(-1 为最后一行),0 表示末行之后。
未读到目标行时返回空字符串。

示例

local line, err = LCC.web_file.get_line("/配置/list.txt", 3)
if line then
print("第 3 行: " .. line)
end