This page has been translated automatically.
Programming
Fundamentials
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Bounds-Related Classes
Containers
Controls-Related Classes
Engine-Related Classes
GUI-Related Classes
Node-Related Classes
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
Rendering-Related Classes
Utility Classes
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 you to write and read data into files. Files are stored locally (unlike Buffer which exists only in the memory).

File Class

Members


File ()

Default constructor.

File (string name, string mode)

Constructor.

Arguments

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

string getName ()

Gets name of the opened file.

Return value

File name.

int eof ()

Tests for end-of-file on a file descriptor.

Return value

1 if it is the end of file; 0 otherwise.

void close ()

Flushes the stream (writing any buffered output data by flush()) and close the file descriptor.

int flush ()

Forces writing of all the buffered data to the file.

Return value

1 if the data is written successfully; otherwise, 0.

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 getc ()

Reads the next character from the file.

Return value

A single character read from the file pointed to by the descriptor.

int tell ()

Tell file position indicator.

Return value

Offset in bytes from the begin of the file.

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 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.
Notice
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 getSize ()

Gets size of the opened file.

Return value

File size in bytes.

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.
Last update: 2017-07-03
Build: ()