This page has been translated automatically.
UnigineScript
The Language
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

File Class

This class allows to write and read data into files. Files are stored locally (unlike Buffer which exists only in the memory).

File Class

This class inherits from Stream

Members


File ()

Default constructor.

File (string name, string mode)

Constructor.

Arguments

  • string name - File name.
  • string mode - Access mode (see File::open).

void close ()

Flushes the stream (writing any buffered output data by File::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.

void flush ()

Forces a write of all buffered data for the file.

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:
  • To open a file for reading, use 'rb'.
  • To create a new file, use 'wb'.

Acceptable access modes in detail are the following:

  • r - Open for reading only. The stream is positioned at the beginning of the file.
  • r+ - Open for reading and writing. The stream is positioned at the beginning of the file.
  • w - Truncate file to zero length or create file for writing. The stream is positioned at the beginning of the file.
  • w+ - 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.
  • a - 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.
  • a+ - 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.
The mode string can also include the letter 'b' either as a last character or as a character between the characters in any of the two-character strings described above. It shall have no effect, but is allowed for ISO C standard conformance.

Arguments

  • string name - File name.
  • string mode - Access mode.

Return value

File descriptor.

void seekCur (int offset)

Shifts the file position indicator by the given offset relatively to the current position indicator.

Arguments

  • int offset - Offset in bytes from the current position of indicator.

void seekEnd (int offset)

Sets the file position indicator to the end of file.

Arguments

  • int offset - Offset in bytes from the end of the file.

void seekSet (int offset)

Sets the file position indicator.

Arguments

  • int offset - Offset in bytes from the begin of the file.

int tell ()

Tell file position indicator.

Return value

Offset in bytes from the begin of the file.
Last update: 2017-07-03
Build: ()