对象:flush()

类型 函数
对象 文件
io.*
返回值
修订版本 版本 2024.3703
关键词 刷新, 文件
另请参阅 io.open()

概述

提交文件的输出缓冲区。将任何写入的数据保存到文件。

语法

File:flush()

示例

local path = system.pathForFile( "data.txt", system.DocumentsDirectory  )
local file, errorString = io.open( path, "w" )  -- open/create for write
 
if not file then
    -- Error occurred; output the cause
    print( "File error: " .. errorString )
end
 
-- The flush call is not really needed in this example but it would be good if
-- there is a long time between when data is written and when the file is closed

fh:write( "Line 1\n" )
fh:flush()  -- Save the data
 
fh:write( "Line 2\n" )
fh:flush()  -- Save the data
 
fh:write( "Line 3\n" )
 
fh:close()  -- Save all the data and close the file