Fopen
From SA-MP Wiki
(Difference between revisions)
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
Note: This function name starts with a lowercase letter. |
Description:
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' folder. |
mode | The mode to open the file with (default: io_readwrite). |
Return Values:
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) // 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.
- fclose: Close a file.
- fwrite: Write to a file.
- fread: Read a file.
- fremove: Remove a file.