FileFlush
刷新缓冲区文件到磁盘.
FileFlush ( "filehandle" )
参数
返回值
成功:
|
返回 true, 缓冲区已刷新 (或不需要刷新).
|
失败:
|
返回 false.
|
备注
当文件已刷新或 Windows 内部缓冲区已满时, 将关闭句柄. 函数强制立即刷新缓冲区.
本函数只能使用 FileOpen() 函数返回的句柄.
相关
FileClose, FileOpen, FileSetPos, FileWrite, FileWriteLine
函数示例
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Example()
Func Example()
; Create a constant variable in Local scope of the filepath that will be read/written to.
Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)
; Open the file for writing (overwrite the file) and store the handle to a variable.
Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE)
If $hFileOpen = -1 Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
Return False
EndIf
; Write data to the file using the handle returned by FileOpen.
FileWriteLine($hFileOpen, "Line 1")
FileWriteLine($hFileOpen, "Line 2")
FileWriteLine($hFileOpen, "Line 3")
; Flush the file to disk.
FileFlush($hFileOpen)
; Check file position and try to read contents for current position.
MsgBox($MB_SYSTEMMODAL, "", "Position: " & FileGetPos($hFileOpen) & @CRLF & "Data: " & @CRLF & FileRead($hFileOpen))
; Now, adjust the position to the beginning.
FileSetPos($hFileOpen, 0, $FILE_BEGIN)
; Check file position and try to read contents for current position.
MsgBox($MB_SYSTEMMODAL, "", "Position: " & FileGetPos($hFileOpen) & @CRLF & "Data: " & @CRLF & FileRead($hFileOpen))
; Close the handle returned by FileOpen.
FileClose($hFileOpen)
; Delete the temporary file.
FileDelete($sFilePath)
EndFunc ;==>Example
----------------------------------------
|