File Class
This class allows to write and read data into files. Files are stored locally (unlike Buffer which exists only in the memory).
See Also
- Article on UnigineScript Migration
File Class
This class inherits from StreamMembers
File ()
Default constructor.File (string name, string mode)
Constructor.Arguments
- string name - File name.
- string mode - Access mode (see open()).
void close ()
Flushes the stream (writing any buffered output data by flush()) and close the file descriptor.int eof ()
Tests for end-of-file on a file descriptor.Return value
1 if it is the end of file; 0 otherwise.int flush ()
Forces writing of all the buffered data to the file.Return value
1 if the data is written successfully; otherwise, 0.string getName ()
Gets name of the opened file.Return value
File name.int getSize ()
Gets size of the opened file.Return value
File size in bytes.int getc ()
Reads the next character from the file.Return value
A single character read from the file pointed to by the descriptor.int open (string name, string mode)
Opens the file with the given access mode.Acceptable access modes in detail are the following:
- rb - Open for reading only. The stream is positioned at the beginning of the file.
- rb+ or r+b - Open for reading and writing. The stream is positioned at the beginning of the file.
- wb - Truncate file to zero length or create file for writing. The stream is positioned at the beginning of the file.
- wb+ or w+b - Open for reading and writing. The file is created if it does not exist, otherwise it is truncated to zero length. The stream is positioned at the beginning of the file.
- ab - Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file.
- ab+ or a+b - Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.
To open the file in the non-binary mode, use the required access mode without the b modifier.
Arguments
- string name - File name.
- string mode - Access mode.
Return value
File descriptor.int seekCur (int offset)
Sets an offset of the file position indicator relative to its current position.Arguments
- int offset - Offset of the file position indicator from the current position, in bytes.
Return value
1 if the offset has been set successfully; otherwise, 0.int seekEnd (int offset)
Sets an offset of the file position indicator relative to the end of the file.Arguments
- int offset - Offset of the file position indicator from the end of the file, in bytes.
Return value
1 if the offset has been set successfully; otherwise, 0.int seekSet (int offset)
Sets an offset of the file position indicator relative to the start of the file.Arguments
- int offset - Offset of the file position indicator from the start of the file, in bytes.
Return value
1 if the offset has been set successfully; otherwise, 0.int tell ()
Tell file position indicator.Return value
Offset in bytes from the begin of the file.Last update: 2017-07-03
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)