File Class extending Object

/ Responsible for File operations /

Class Methods

Moves the filename to the destination
E.g
move("./test.txt", "./test2.txt");

function move(string filename, string dst_filename) : void


Returns true if the given path is a file, returns false if it is a directory or an error occured

function isFile(string filename) : boolean

Attempts to open the file with the given filename. Returns true if successful otherwise false.
The mode provided determines how you wish to open this file.
Use "w" to open the file for writing this will overwrite the file if it exists
Use "r" to open the file for reading
Use "a" to open the file for appending this will create a new file if one does not exist
You are required a FilePermission that allows you access to the file you are trying to open along with the mode

function open(string filename, string mode) : void


Returns the output stream for this opened file allowing you to write to the file

function getOutputStream() : FileOutputStream

Returns the input stream for this opened file allowing you to read the file

function getInputStream() : FileInputStream


Sets the position in the file that you wish to access

function setPosition(number pos) : void

Gets the current size of this file (not of the input stream or output stream)

function getSize() : number


Closes this current file

function close() : void

Deletes the file with the specified filename throws an IOException if it does not exist or the file could not be deleted

function delete(string filename) : void


Reads the entire file into memory as a string and returns the file contents.
Important to note that this returns only valid ASCII string data. Please use file_get_binary_contents for binary files

function file_get_contents(string filename) : string

Reads the entire file into memory, returns the file contents as a number array that holds 8 bit characters in each index.
Use this function for reading binary files
Available Since v0.4.0

function file_get_binary_contents(string filename) : number[]


Writes the given string to the file specified by the filename.
If the file does not exist it creates it, if it does exist it overwrites it

function file_put_contents(string filename, string data) : void

Writes the given number array to the file specified by the filename. Each number in your number array
will be treated as a single 8 bit character all other bits of the number are ignored. For example if you have a number with the value 0xffff. Only 0xff will be used
If the file does not exist it creates it, if it does exist it overwrites it
Available Since v0.4.0

function file_put_binary_contents(string filename, number[] data) : void


Changes the mode of the given file

function chmod(string filename, number mode) : string