Fopen

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 21:45, 30 January 2014
Smithy (Talk | contribs)

← Previous diff
Revision as of 15:17, 1 February 2014
Connor Mead (Talk | contribs)

Next diff →
Line 37: Line 37:
[[Category:File Functions]] [[Category:File Functions]]
 +[[fr:fopen]]
[[ru:fopen]] [[ru:fopen]]

Revision as of 15:17, 1 February 2014


Image:Farm-Fresh text lowercase.png Note: This function name starts with a lowercase letter.


Description:

Open a file (to read from or write to).


Parameters:
(name[], filemode:mode = io_readwrite)
name[]The path to the file to open (if just a filename is specified, it will open the file with the name specified in the 'scriptfiles' folder.
modeThe mode to open the file with (default: io_readwrite).


Return Values:

Returns the Filehandle. 0 if failed to open file


Image:32px-Circle-style-warning.png

Important
Note

If you use io_read and the file doesn't exist, the server will crash.


Modes

io_read      Reads from the file.
io_write     Write in the file, or create the file. Erases all contents.
io_readwrite Reads the file or creates it
io_append    Appends (adds) to file, write-only. If the file does not exist, it is created
new File:example = fopen("file.txt", io_write);
 
if(example) // If it opened successfully
{
    fwrite(example, "I just wrote here!");
    fclose(example); // The file MUST be closed when finished!
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.

In other languages