类型 函数 库 io.* 返回值 对象 修订版 版本 2024.3703 关键词 io、input、file 另请参阅 io.output() io.read()
设置标准输入文件。当使用文件句柄调用该函数时,它会直接将此文件句柄设置成默认输入文件。当在无参数条件下调用该函数时,它会返回当前的默认输入文件。
此函数返回已打开文件的句柄或当前输入文件的句柄。
io.input( file )
对象. 应将文件设置为标准输入文件。你必须使用 system.pathForFile() 为 system.ResourceDirectory
、system.DocumentsDirectory
、system.ApplicationSupportDirectory
、system.TemporaryDirectory
或 system.CachesDirectory
常量 创建文件名和路径。
local path = system.pathForFile( "data.txt", system.DocumentsDirectory ) local tmp = io.input() -- Save current file handle io.input( path ) -- Open new file in text mode print( io.read() ) -- Read and display the file io.input():close() -- Close the file io.input( tmp ) -- Restore the previous file