Fopen

From SA-MP Wiki

Jump to: navigation, search


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\ directory.
modeThe mode to open the file with (default: io_readwrite).


ReturnsReturns 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)
{
	fwrite(example, "I just wrote here!");
	fclose(example);
}

Related Functions

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

Personal tools
In other languages