Fopen
From SA-MP Wiki
Open a file (to read from or write to).
(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. |
| mode | The mode to open the file with (default: io_readwrite). |
| Returns | Returns the Filehandle. 0 if failed to open file |
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.
- fclose: Close a file.
- fwrite: Write to a file.
- fread: Read a file.
- fremove: Remove a file.
