获取一个文本文件的所有行 (pfile.get_lines)

声明

行数组 = pfile.get_lines(文件路径)

参数及返回值

  • 文件路径
    • 文本型,文件绝对路径
  • 行数组
    • 顺序表型 或 nil,返回一个顺序表,文件不存在返回 nil

说明

pfile模块操作手机设备文件,如果你要操作ATP服务器的文件,请使用file模块。

获取一个文本文件的所有行,空文件返回 0 行

示例

local lines = pfile.get_lines("/sdcard/1.txt")
if lines then
    if #lines > 0 then
        print("文件第一行的内容是 "..lines[1])
    else
        print("文件是空的")
    end
else
    print("操作失败")
end
powered by GitbookFile Modify: 2021-03-27 23:14:19

results matching ""

    No results matching ""