openFile

From GTA Connected
Revision as of 15:20, 24 August 2019 by Mex (talk | contribs) (Mex moved page OpenFile to openFile)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Function Server and Client icon-iii.png icon-vc.png icon-sa.png icon-iv.png Online and Offline

Available since Server 1.0.0, Client 1.0.0

Stream openFile(string filePath, [ bool writable = false ])

The openFile function is used to open a handle to a file on the hard drive, fetching a Stream object on success.
The file is opened in binary mode, not text mode.
The initial seek position is 0.
If parameter Writable is bool true, the file is created if it doesn't exist.

Parameters

1) string filePath The path to the file.
2) bool writable Optional, defaults to false. Whether to open the file in writable mode.

Return

Stream A handle to the file stream.

Notes

There aren't any notes for this function.

Examples

Example 1 - JavaScript:

file = openFile("test.txt", true) if (file != null) {

   file.writeString("this is a test")
   file.close()

}


Example 2 - Lua:

file = openFile("test.txt", true) if file ~= nil then

   file:writeString("this is a test")
   file:close()

end

Compatibility

There isn't any compatibility information for this function.

Related

Server Related

icon-iii.png icon-vc.png icon-sa.png icon-iv.png createFile
icon-iii.png icon-vc.png icon-sa.png icon-iv.png fileExists
icon-iii.png icon-vc.png icon-sa.png icon-iv.png loadTextFile
icon-iii.png icon-vc.png icon-sa.png icon-iv.png openFile
icon-iii.png icon-vc.png icon-sa.png icon-iv.png saveTextFile


Client Related

icon-iii.png icon-vc.png icon-sa.png icon-iv.png createFile
icon-iii.png icon-vc.png icon-sa.png icon-iv.png fileExists
icon-iii.png icon-vc.png icon-sa.png icon-iv.png loadTextFile
icon-iii.png icon-vc.png icon-sa.png icon-iv.png openFile
icon-iii.png icon-vc.png icon-sa.png icon-iv.png saveTextFile