FileClose: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Destroy method doesn't work anymore in 1.5.3.)
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server function}}
{{Server client function}}
Cierra un archivo abierto obtenido por [[fileCreate]] o [[fileOpen]].
Closes a file handle obtained by [[fileCreate]] or [[fileOpen]].


==Sintaxis==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool fileClose ( archivo elArchivo )
bool fileClose ( file theFile )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[file]]:close}}


===Argumentos requeridos===
===Required Arguments===
*'''elArchivo:''' El archivo que quiere cerrar.
*'''theFile:''' The file handle to close.


===Retorna===
===Returns===
Retorna ''true'' si se cerro satisfactoriamente, ''false'' sino.
Returns ''true'' if successful, ''false'' otherwise.


==Ejemplo==
==Example==
Este ejemplo crea un archivo de texto y escribe un string en el.
This example creates a text file and writes a string to it.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local nuevoArchivo = fileCreate("prueba.txt")             -- Intenta crear el archivo.
local newFile = fileCreate("test.txt")               -- attempt to create a new file
if nuevoArchivo then                                      -- Verificar si fue satisfactoriamente creado.
if newFile then                                      -- check if the creation succeeded
     fileWrite(nuevoArchivo, "Este es un archivo de prueba!") -- Escribe una linea de texto.
     fileWrite(newFile, "This is a test file!")       -- write a text line
     fileClose(nuevoArchivo)                                -- Cierra el archivo luego de haber escrito en el.
     fileClose(newFile)                                -- close the file once you're done with it
end
end
</syntaxhighlight>
</syntaxhighlight>


Es importante recordar cerrar el archivo luego de haber echo todas las operaciones en el.
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.
Especial mente si escribio en el. Si no cierra el archivo y el recurso falla todos los cambias se perderan.


==Ver también==
==See Also==
{{Funciones_de_archivos}}
{{File functions}}
 
[[es:fileClose]]

Revision as of 11:55, 22 October 2016

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.

See Also