FileClose: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server function}} | {{Server client function}} | ||
Closes a file | Closes a file handle obtained by [[fileCreate]] or [[fileOpen]]. | ||
==Syntax== | ==Syntax== | ||
Line 7: | Line 7: | ||
bool fileClose ( file theFile ) | bool fileClose ( file theFile ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[file]]:close}} | |||
===Required | ===Required Arguments=== | ||
*'''theFile:''' | *'''theFile:''' The file handle to close. | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if | Returns ''true'' if successful, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example creates a | This example creates a text file and writes a string to it. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local newFile = fileCreate("test.txt") | local newFile = fileCreate("test.txt") -- attempt to create a new file | ||
if newFile then -- | if newFile then -- check if the creation succeeded | ||
fileWrite(newFile, "This is a test file!") -- | fileWrite(newFile, "This is a test file!") -- write a text line | ||
fileClose(newFile) -- | fileClose(newFile) -- close the file once you're done with it | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
It is important to remember to close | 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 | ==See Also== | ||
{{ | {{File functions}} | ||
[[pt-br:fileClose]] | |||
[[fileClose]] |
Latest revision as of 17:24, 20 December 2023
Closes a file handle obtained by fileCreate or fileOpen.
Syntax
bool fileClose ( file theFile )
OOP Syntax Help! I don't understand this!
- Method: file:close(...)
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.