File

A File represents an entry to a system file.

Note

Currently it is not possible to Delete or Rename files, that will be added for a future update.

Note

This is a server side class. It is not possible to open files from outsite the server folder. All path must be relative to the Server’s executable folder. All files are opened as binary file by default.

Example

local configuration_file = File("my_awesome_configuration.json")

local configuration_file_json = JSON.parse(configuration_file:Read(configuration_file:Size()))

Constructor Parameters

Type

Name

Default

string

FilePath

boolean

Truncate

false

Functions

Returns

Name

Description

Close()

Closes the file

Flush()

Flushes content to the file

boolean

IsEOF()

Checks if the file status is End of File

boolean

IsBad()

Checks if the file status is Bad

boolean

IsGood()

Checks if the file status is Good

boolean

HasFailed()

Checks if the last operation has Failed

string

Read(number Length = 0)

Reads n (Length) characters from the File and returns it. Also moves the file pointer to the latest read position. Pass 0 to read the whole file

string

ReadLine()

Reads and returns the next file line

Seek(number Position)

Sets the file pointer to a specific position

number

Size()

Returns the size of the file

number

Size()

Returns the size of the file

Skip(number Amount)

Skips n (Amount) positions from the current file pointer position

number

Tell()

Returns the current file pointer position

Write(string Data)

Writes the Data at the current position of the file