文件系统

readfile

从执行器工作区读取文件的完整内容。

语法

readfile(path: string): string
别名 readfileasync

参数

名称类型描述
pathstring文件或文件夹的工作空间相对路径。

返回值

名称类型描述
contentstring完整的文件内容。

说明

从执行器工作区读取文件的完整内容。

使用 1 个参数调用: path。参数表会说明哪些值必填,哪些值只用于细化行为。

返回 content (string)。使用返回表区分成功值、nil 结果和可恢复错误。

示例

检查工作区文件是否存在后读取该文件。

local path = "workspace/examples/config.json"

if isfile(path) then
    local content = readfile(path)
    print(content)
end