## File(filename, mode)

Constructor

#### # new File(filename, mode)

Open a file, for file modes see FILE. Files can only either be read or written, never both. Writing to a closed file throws an exception.

##### Parameters:

Name | Type | Description
--- | --- | ---
`filename` | `string` | the name of the file.
`mode` | `FILE` | READ, WRITE or APPEND.

# Members

Type: `string`

#### # filename

Name of the file.

Type: `FILE`

#### # mode

file open mode

# Methods

#### # Close()

Close the file.

#### # GetSize() → {number}

get file size.

Returns:

the size of the file in bytes.

Type: `number`

#### # ReadByte() → {number}

Read a single byte from file and return it as number.

Returns:

the byte as a number or null for EOF.

Type: `number`

#### # ReadBytes(numopt) → {Array.<number>}

get file (remaining) contents as number array.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`num` | `number` | <optional> | max number of bytes to return.

Returns:

the (remaining) contents of the file as array of numbers.

Type: `Array.<number>`

#### # ReadInts(numopt) → {ByteArray}

get file (remaining) contents as number ByteArray.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`num` | `number` | <optional> | max number of bytes to return.

Returns:

the (remaining) contents of the file as ByteArray.

Type: `ByteArray`

#### # ReadLine() → {string}

Read a line of text from file. The maximum line length is 4096 byte.

Returns:

the next line or null for EOF.

Type: `string`

#### # WriteByte(ch)

Write a single byte to a file.

##### Parameters:

Name | Type | Description
--- | --- | ---
`ch` | `number` | the byte to write.

#### # WriteBytes(data, numopt)

Write a bytes to a file.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`data` | `Array.<number>` |  | the data to write as array of numbers (must be integers between 0-255).
`num` | `number` | <optional> | max number of bytes to write.

#### # WriteInts(data, numopt)

Write a bytes to a file.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`data` | `ByteArray` |  | the data to write as ByteArray (must be integers between 0-255).
`num` | `number` | <optional> | max number of bytes to write.

#### # WriteLine(txt)

Write a NEWLINE terminated string to a file.

##### Parameters:

Name | Type | Description
--- | --- | ---
`txt` | `string` | the string to write.

#### # WriteString(txt)

Write a string to a file.

##### Parameters:

Name | Type | Description
--- | --- | ---
`txt` | `string` | the string to write.