io.output()

类型 函数
io.*
返回值 对象
修订版 2024.3703 版
关键字 io,output,file
另请参阅 io.input()
io.flush()
io.write()

概述

设置标准输出文件。当使用文件名调用时,会以文本模式打开指定的文件并将其句柄设为默认输出文件。当使用文件句柄调用时,只会将此文件句柄设为默认输出文件。当在没有参数的情况下调用时,会返回当前的默认输出文件。

默认的输出是 stdout,即 Corona 模拟器控制台。这类似于 io.input() 的行为,但操作的是默认的输出文件。

此函数会返回刚打开文件的句柄或当前输入文件句柄的句柄。

语法

io.output( [file] )
file (可选)

字符串对象文件名或文件句柄。

示例

local tmp = io.output()     -- Save current file handle
local path = system.pathForFile( "newFile.txt", system.DocumentsDirectory  )
io.output( path )           -- Open new file in text mode
 
io.write( "My real data" )  -- Write the file
 
io.output():close()         -- Close the file
io.output( tmp )            -- Restore the previous file