File object

The File objects allow you to work with files. You can read from and write to both text and binary files. Reading is also supported from files stored in your game packages (DCP files). The File object can be created using the following syntax:

var SomeFile = new File("c:\path\filename.txt");


Конструкторы

File Creates a new file object for a specified filename.

Методы

Operations
SetFilename Sets the filename the File object operates on.
OpenAsText Opens file for text reading or writing.
OpenAsBinary Opens file for binary reading or writing.
Close Closes the file.
SetPosition Sets a new reading/writing point for a currently open file.
Delete Deletes the file accosiated with this File object.
Copy Copies the file to a new location.
Text file access
ReadLine Reads a line from a text file open for reading.
ReadText Reads text from a text file open for reading.
WriteLine Writes a line to a text file open for writing/appending.
WriteText Writes text to a text file open for writing/appending.
Binary file access
ReadBool Reads a boolean value (1 byte) from a binary file open for reading.
ReadByte Reads an 8-bit integer value from a binary file open for reading.
ReadShort Reads a 16-bit integer value from a binary file open for reading.
ReadInt Reads a 32-bit integer value from a binary file open for reading.
ReadFloat Reads a 16-bit floating point value from a binary file open for reading.
ReadDouble Reads a 32-bit floating point value from a binary file open for reading.
ReadString Reads a zero-terminated string value from a binary file open for reading.
WriteBool Writes a boolean value (1 byte) to a binary file open for writing/appending.
WriteByte Writes an 8-bit integer value to a binary file open for writing/appending.
WriteShort Writes a 16-bit integer value to a binary file open for writing/appending.
WriteInt Writes a 32-bit integer value to a binary file open for writing/appending.
WriteFloat Writes a 16-bit floating point value to a binary file open for writing/appending.
WriteDouble Writes a 32-bit floating point value to a binary file open for writing/appending.
WriteString Writes a zero-terminated string value to a binary file open for writing/appending.

Атрибуты

Type (только для чтения) Returns always "file"
Filename (только для чтения) Returns the filename currently assigned to this object.
Position (только для чтения) Returns current reading/writing position within the file.
Length (только для чтения) Returns length of file.
TextMode (только для чтения) Returns true if the file is open in text mode.
AccessMode (только для чтения) Returns the access mode the file is open in (0 - not open, 1 - reading, 2 - writing, 3 - appending)

File(Filename)

Creates a new file object for a specified filename.

Параметры

Filename
The file this File object should operate on

SetFilename(Filename)

Sets the filename the File object operates on.

Параметры

Filename
The file to be used by this File object

OpenAsText(AccessMode)

Opens file for text reading or writing.

Параметры

AccessMode
Specifies the desired file access, 1 - reading, 2 - writing, 3 - appending

Возвращаемое значение

Returns true is the file was successfuly open.


OpenAsBinary(AccessMode)

Opens file for binary reading or writing.

Параметры

AccessMode
Specifies the desired file access, 1 - reading, 2 - writing, 3 - appending

Возвращаемое значение

Returns true is the file was successfuly open.


Close()

Closes the file.

Примечания

Files are closed automatically when their File objects are destroyed but it's a good idea to close the file explicitly immediately after you're done with working with it.


SetPosition(Position)

Sets a new reading/writing point for a currently open file.

Параметры

Position
The desired reading/writing position

Возвращаемое значение

Returns true if the position has been successfuly set.


Delete()

Deletes the file accosiated with this File object.

Возвращаемое значение

Returns true if the file has been successfuly deleted.


Copy(DestinationFilename, Overwrite)

Copies the file to a new location.

Параметры

DestinationFilename
The new location to copy the file to.
Overwrite
Specifies if the file should overwrite any existing file with the same name (optional, default=true)

Возвращаемое значение

Returns true if the file has been successfuly copied.


ReadLine()

Reads a line from a text file open for reading.

Возвращаемое значение

Returns a string value containing the line or null if file cannot be read / position is at the end of file.


ReadText(Length)

Reads text from a text file open for reading.

Параметры

Length
Number of characters to be read from the file.

Возвращаемое значение

Returns a string value containing the text or null if file cannot be read / position is at the end of file.


WriteLine(Line)

Writes a line to a text file open for writing/appending.

Параметры

Line
The text line to be written to the file

Возвращаемое значение

Returns true if the value has been successfuly written.


WriteText(Text)

Writes text to a text file open for writing/appending.

Параметры

Text
The text to be written to the file

Возвращаемое значение

Returns true if the value has been successfuly written.


ReadBool()

Reads a boolean value (1 byte) from a binary file open for reading.

Возвращаемое значение

Returns the value or null if file cannot be read / position is at the end of file.


ReadByte()

Reads an 8-bit integer value from a binary file open for reading.

Возвращаемое значение

Returns the value or null if file cannot be read / position is at the end of file.


ReadShort()

Reads a 16-bit integer value from a binary file open for reading.

Возвращаемое значение

Returns the value or null if file cannot be read / position is at the end of file.


ReadInt()
ReadLong()

Reads a 32-bit integer value from a binary file open for reading.

Возвращаемое значение

Returns the value or null if file cannot be read / position is at the end of file.


ReadFloat()

Reads a 16-bit floating point value from a binary file open for reading.

Возвращаемое значение

Returns the value or null if file cannot be read / position is at the end of file.


ReadDouble()

Reads a 32-bit floating point value from a binary file open for reading.

Возвращаемое значение

Returns the value or null if file cannot be read / position is at the end of file.


ReadString()

Reads a zero-terminated string value from a binary file open for reading.

Возвращаемое значение

Returns the value or null if file cannot be read / position is at the end of file.


WriteBool(Value)

Writes a boolean value (1 byte) to a binary file open for writing/appending.

Параметры

Value
The value to be written to the file.

Возвращаемое значение

Returns true if the value has been successfuly written.


WriteByte(Value)

Writes an 8-bit integer value to a binary file open for writing/appending.

Параметры

Value
The value to be written to the file.

Возвращаемое значение

Returns true if the value has been successfuly written.


WriteShort(Value)

Writes a 16-bit integer value to a binary file open for writing/appending.

Параметры

Value
The value to be written to the file.

Возвращаемое значение

Returns true if the value has been successfuly written.


WriteInt(Value)
WriteLong(Value)

Writes a 32-bit integer value to a binary file open for writing/appending.

Параметры

Value
The value to be written to the file.

Возвращаемое значение

Returns true if the value has been successfuly written.


WriteFloat(Value)

Writes a 16-bit floating point value to a binary file open for writing/appending.

Параметры

Value
The value to be written to the file.

Возвращаемое значение

Returns true if the value has been successfuly written.


WriteDouble(Value)

Writes a 32-bit floating point value to a binary file open for writing/appending.

Параметры

Value
The value to be written to the file.

Возвращаемое значение

Returns true if the value has been successfuly written.


WriteString(Value)

Writes a zero-terminated string value to a binary file open for writing/appending.

Параметры

Value
The value to be written to the file.

Возвращаемое значение

Returns true if the value has been successfuly written.