File


super: Object

The File class is an object-oriented wrapper for a file descriptor. You use file handle objects to access data associated with files. You can read, write, and seek within the file.

Events

  • Load() This event is called when the object becames available in the current runtime system.

  • Unload() This event is called when the object has been removed from the current runtime system (but not yet deallocated).

Properties

  • var path: String File full path. (read-only)

  • var name: String File name. (read-only)

  • var extension: String File extension. (read-only)

  • var error: String Current error as String (if any). (read-only)

  • var offset: Int File current offset. (read-only)

  • var objectName: String The name of the object.

Class Methods

  • func open(filePath: Object, mode: FileMode = 0): File Opens the specified file using the optional FileMode and returns a File object.

Methods

  • func seekToEnd(): Int Puts the file pointer at the end of the file referenced by the receiver and returns the new file offset.

  • func close() Disallows further access to the represented file.

  • func readData(): Data Reads the available data up to the end of file or maximum number of bytes. Returns a Data object.

  • func readString(): String Reads the available data up to the end of file or maximum number of bytes. Returns a String object.

  • func seekTo(position: Int) Moves the file pointer to the specified offset within the file represented by the receiver.

  • func readDataOfLength(length: Int): Data Reads data up to the specified number of bytes. Returns a Data object.

  • func readStringOfLength(length: Int): String Reads data up to the specified number of bytes. Returns a String object.

  • func writeData(data: Data): Bool Writes the specified data to the receiver. Returns true if the operation was successfully.

  • func writeString(string: String): Bool Writes the specified string to the receiver. Returns true if the operation was successfully.

Enums

FileMode

  • .Read
  • .Update
  • .Write