<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/PT-BR/fileOpen?action=history&amp;feed=atom</id>
	<title>PT-BR/fileOpen - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/PT-BR/fileOpen?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PT-BR/fileOpen&amp;action=history"/>
	<updated>2026-04-06T22:47:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PT-BR/fileOpen&amp;diff=78714&amp;oldid=prev</id>
		<title>Lettify: Created page with &quot;__NOTOC__ {{BR/Funcao compartilhada}}  Abre um arquivo existente para leitura e gravação.  {{BR/Nota|Para prevenir perdas de memórias, garanta que cada execução bem sucedida de fileOpen tenha um fileClose para fechar o arquivo aberto.}} {{BR/Tip|As funções que manipulam arquivos não devem ser utilizadas para implementar arquivos de configuração. É recomendado usar as Shared_Scripting_Functions#XML_functions|funções XM...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PT-BR/fileOpen&amp;diff=78714&amp;oldid=prev"/>
		<updated>2023-12-20T19:25:30Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {{BR/Funcao compartilhada}}  Abre um arquivo existente para leitura e gravação.  {{BR/Nota|Para prevenir perdas de memórias, garanta que cada execução bem sucedida de &lt;a href=&quot;/wiki/PT-BR/fileOpen&quot; title=&quot;PT-BR/fileOpen&quot;&gt;fileOpen&lt;/a&gt; tenha um &lt;a href=&quot;/wiki/PT-BR/fileClose&quot; title=&quot;PT-BR/fileClose&quot;&gt;fileClose&lt;/a&gt; para fechar o arquivo aberto.}} {{BR/Tip|As funções que manipulam arquivos não devem ser utilizadas para implementar arquivos de configuração. É recomendado usar as Shared_Scripting_Functions#XML_functions|funções XM...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{{BR/Funcao compartilhada}}&lt;br /&gt;
&lt;br /&gt;
Abre um arquivo existente para leitura e gravação.&lt;br /&gt;
&lt;br /&gt;
{{BR/Nota|Para prevenir perdas de memórias, garanta que cada execução bem sucedida de [[PT-BR/fileOpen|fileOpen]] tenha um [[PT-BR/fileClose|fileClose]] para fechar o arquivo aberto.}}&lt;br /&gt;
{{BR/Tip|As funções que manipulam arquivos não devem ser utilizadas para implementar arquivos de configuração. É recomendado usar as [[Shared_Scripting_Functions#XML_functions|funções XML]].}}&lt;br /&gt;
{{MessageBox|bordercolorhex=FFB2B2|bgcolorhex=FFE5E5|image=File:Dialog-warning.png|title=Aviso:|message=A partir da versão 1.5.4 [https://buildinfo.mtasa.com/?Author=&amp;amp;Branch=&amp;amp;Revision=10413 r10413], esta função vai falhar quando tentar acessar um arquivo de script de outro resource, até mesmo com a permissão ''general.ModifyOtherObjects'' concedida, que usa uma conexão ''mysql'' através de [[dbConnect]] quando [[Server_mtaserver.conf#database_credentials_protection|''database_credentials_protection'']] estiver habilitado na configuração do servidor. Além disso, não será mais possível gravar no '''meta.xml''', ele será aberto apenas em modo leitura.}}&lt;br /&gt;
&amp;lt;!-- The {Warning} template didn't want to work with an external link to buildinfo, so I had to use the {MessageBox} template --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Sintaxe==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
file fileOpen ( string filePath [, bool readOnly = false ])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{PT-BR/POO|A função vai apenas tentar abrir o arquivo, não vai criá-lo.|[[File]]}}&lt;br /&gt;
&lt;br /&gt;
{{PT-BR/New feature/item|9.0156|1.5.6|11865|&lt;br /&gt;
{{PT-BR/POO|Esta é uma função estática abaixo da classe File. Usando '''File(...)''' vai abrir um arquivo caso existe, senão este será criado.|[[File]].open}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
===Argumentos necessários===&lt;br /&gt;
*'''filePath:''' O [[filepath|caminho]] do arquivo a ser criado seguindo o seguinte formato: '''&amp;quot;:resourceName/path&amp;quot;'''. '''resourceName''' é o nome do resource do arquivo que vai estar lá, e '''path''' é o caminho do arquivo relativo ao diretório do resource.&lt;br /&gt;
:Por exemplo, se existir um arquivo chamado ''coolObjects.txt'' no resource ''objectSearch'', esse arquivo pode ser aberto de um outro resource dessa forma: &amp;lt;code&amp;gt;fileOpen(&amp;quot;:objectSearch/coolObjects.txt&amp;quot;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
:Se o arquivo está no resource atual, apenas o caminho do arquivo é necessário, ex.: &amp;lt;&amp;lt;code&amp;gt;fileOpen(&amp;quot;coolObjects.txt&amp;quot;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Argumento opcional===&lt;br /&gt;
*'''readOnly:''' Por padrão, o arquivo é aberto com acesso de leitura e gravação. Você pode especificar '''true''' para esse argumento se você quiser o acesso apenas para leitura.&lt;br /&gt;
&lt;br /&gt;
===Retorno===&lt;br /&gt;
Se aberto com sucesso, retorna o '''arquivo''' (objeto-arquivo) especificado. Caso contrário retorna '''false''' (ex.: se o arquivo não existir).&lt;br /&gt;
&lt;br /&gt;
==Exemplo==&lt;br /&gt;
Este exemplo abre o arquivo &amp;quot;test.txt&amp;quot; que está na raiz do resource atual (onde o código tá sendo executado), e exibe o seu conteúdo no console.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local hFile = fileOpen(&amp;quot;test.txt&amp;quot;, true)       -- tentamos abrir o arquivo (em modo leitura)&lt;br /&gt;
if hFile then                                  -- verificamos se foi aberto com sucesso&lt;br /&gt;
    local buffer&lt;br /&gt;
    while not fileIsEOF(hFile) do              -- enquanto não estivermos o final do arquivo...&lt;br /&gt;
        buffer = fileRead(hFile, 500)          -- ... lemos os próximos 500 bytes ...&lt;br /&gt;
        outputConsole(buffer)                  -- ... e exibimos no console&lt;br /&gt;
    end&lt;br /&gt;
    fileClose(hFile)                           -- fechamos o arquivo depois de trabalhar com ele&lt;br /&gt;
else&lt;br /&gt;
    outputConsole(&amp;quot;Unable to open test.txt&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example show how to append data to an existing file:&lt;br /&gt;
Este exemplo mostra como inserir (sem substituir) um dado em um arquivo existente:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local hFile = fileOpen(&amp;quot;test.txt&amp;quot;)             -- tentamos abrir o arquivo (em modo leitura e gravação)&lt;br /&gt;
if hFile then                                  -- verificamos se foi aberto com sucesso&lt;br /&gt;
    fileSetPos( hFile, fileGetSize( hFile ) )  -- movemos a posição para o fim do arquivo&lt;br /&gt;
    fileWrite(hFile, &amp;quot;hello&amp;quot; )                 -- inserimos o valor que queremos&lt;br /&gt;
    fileFlush(hFile)                           -- Forçamos a gravação imediata do valor que inserimos no arquivo&lt;br /&gt;
    fileClose(hFile)                           -- fechamos o arquivo depois de trabalhar nele&lt;br /&gt;
else&lt;br /&gt;
    outputConsole(&amp;quot;Unable to open test.txt&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Veja também==&lt;br /&gt;
{{PT-BR/File functions}}&lt;/div&gt;</summary>
		<author><name>Lettify</name></author>
	</entry>
</feed>