CFile Class


The CFile class provides file reading and writing operations. Normally, this class is used for binary-mode file operations. You also can use it for text-mode file operations but the Lua language includes the io package for working with text files.

Usage

Construction

Object = CFile:new()

Destruction

Object:delete()

Class Properties

This class has 3 enumeratied constants, or properties, that control positioning of the file pointer using the Seek method.

File Access Modes

The CFile class also uses several file access modes to select binary or text mode for reading, writing, or appending files.

Global Methods

FileOpen

Opens a file in the specified mode and returns a new instance of a CFile class. This can be used in place of using the new constructor followed by the Open method.

Class Methods

Construction

new

Creates a new instance of a CFile object.

delete

Deletes the instance of the CFile object.

Operations

Close

Closes the file.

FilePos

Returns the current file position.

Flush

Commits data in the operating system buffer to the file.

GetPath

Returns the name of the file.

Open

Opens the file.

Printf

Writes formatted text to the file.

Read

Reads a value or table of values of specified data type from a binary file.

ReadBswap

Reads a value or table of values of specified data type from a binary file. The values are automatically byte-swapped.

Seek

Resets the file position to a given location.

Write

Writes a value or table to a binary file using the specified data type.

WriteBswap

Writes a value or table to a binary file using the specified data type. The values are automatically byte-swapped before being written to the file.

Related Topics

Printf

CFindFiles class