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 (read only) | Returns always "file" |
Filename (read only) | Returns the filename currently assigned to this object. |
Position (read only) | Returns current reading/writing position within the file. |
Length (read only) | Returns length of file. |
TextMode (read only) | Returns true if the file is open in text mode. |
AccessMode (read only) | Returns the access mode the file is open in (0 - not open, 1 - reading, 2 - writing, 3 - appending) |
Creates a new file object for a specified filename.
Sets the filename the File object operates on.
Opens file for text reading or writing.
Returns true is the file was successfuly open.
Opens file for binary reading or writing.
Returns true is the file was successfuly open.
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.
Sets a new reading/writing point for a currently open file.
Returns true if the position has been successfuly set.
Deletes the file accosiated with this File object.
Returns true if the file has been successfuly deleted.
Copies the file to a new location.
Returns true if the file has been successfuly copied.
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.
Reads text from a text file open for reading.
Returns a string value containing the text or null if file cannot be read / position is at the end of file.
Writes a line to a text file open for writing/appending.
Returns true if the value has been successfuly written.
Writes text to a text file open for writing/appending.
Returns true if the value has been successfuly written.
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.
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.
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.
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.
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.
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.
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.
Writes a boolean value (1 byte) to a binary file open for writing/appending.
Returns true if the value has been successfuly written.
Writes an 8-bit integer value to a binary file open for writing/appending.
Returns true if the value has been successfuly written.
Writes a 16-bit integer value to a binary file open for writing/appending.
Returns true if the value has been successfuly written.
Writes a 32-bit integer value to a binary file open for writing/appending.
Returns true if the value has been successfuly written.
Writes a 16-bit floating point value to a binary file open for writing/appending.
Returns true if the value has been successfuly written.
Writes a 32-bit floating point value to a binary file open for writing/appending.
Returns true if the value has been successfuly written.
Writes a zero-terminated string value to a binary file open for writing/appending.
Returns true if the value has been successfuly written.