FileClose: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: bool fileClose ( file ) Closes a file opened by fileOpen. You should always close your files when you're done with them.)
 
No edit summary
Line 1: Line 1:
bool fileClose ( file )
__NOTOC__
{{Server function}}
Closes a file handle obtained by [[fileCreate]] or [[fileOpen]].


Closes a file opened by fileOpen. You should always close your files when you're done with them.
==Syntax==
<syntaxhighlight lang="lua">
bool fileClose ( file theFile )
</syntaxhighlight>
 
===Required Arguments===
*'''theFile:''' The file handle to close.
 
===Returns===
Returns ''true'' if successful, ''false'' otherwise.
 
==Example==
This example creates a text file and writes a string to it.
<syntaxhighlight lang="lua">
local newFile = fileCreate("test.txt")                -- attempt to create a new file
if newFile then                                      -- check if the creation succeeded
    fileWrite(newFile, "This is a test file!")        -- write a text line
    fileClose(newFile)                                -- close the file once you're done with it
end
</syntaxhighlight>
 
It is important to remember to close a file after you've finished all your operations on it, especially if you've been writing to the file. If you don't close a file and your resource crashes, all changes to the file may be lost.
 
==See Also==
{{File functions}}

Revision as of 11:28, 24 November 2007

Closes a file handle obtained by fileCreate or fileOpen.

Syntax

bool fileClose ( file theFile )

Required Arguments

  • theFile: The file handle to close.

Returns

Returns true if successful, false otherwise.

Example

This example creates a text file and writes a string to it.

local newFile = fileCreate("test.txt")                -- attempt to create a new file
if newFile then                                       -- check if the creation succeeded
    fileWrite(newFile, "This is a test file!")        -- write a text line
    fileClose(newFile)                                -- close the file once you're done with it
end

It is important to remember to close a file after you've finished all your operations on it, especially if you've been writing to the file. If you don't close a file and your resource crashes, all changes to the file may be lost.

See Also