User Tools

Site Tools


en:code:data:file

This is an old revision of the document!


File

The File object allows you to read and write a file.

Functions

File

Constructor function.

Syntax

var myObject = new File();

Example

Create a File object.

var myObject = new File();

Methods

open

Opens a file.

Syntax

myObject.open(filename, mode);

Arguments

  1. filename - (string) the filename of the file to open
  2. mode - (Mode) the open mode

Returns

  • (File) this File

Exceptions

  • (CannotOpenFileError) cannot open the file

write

Write raw data to this File.

Syntax

myObject.write(data);
myObject.write(other);

Arguments

  1. data - (RawData) the data to write
  2. other - (mixed) the data to write

Returns

  • (File) this File

Exceptions

  • (WriteFailedError) write failed

writeText

Write text to this File.

Syntax

myObject.writeText(text);
myObject.writeText(text, encoding);

Arguments

  1. text - (string) the text to write
  2. encoding - (Encoding) the encoding to use

Returns

  • (File) this File

Exceptions

  • (WriteFailedError) write failed

read

Read raw data from this File.

Syntax

myObject.read();

Returns

  • (RawData) the raw data read from the file

readText

Read text from this File.

Syntax

myObject.readText();
myObject.readText(encoding);

Arguments

  1. encoding - (Encoding) the encoding to use

Returns

  • (string) the text read from the file

close

Close this file.

Syntax

myObject.close();

Returns

  • (File) this File

copy

Copy this file to another location.

Syntax

myObject.copy(destination);
myObject.copy(destination, createDestinationDirectory);

Arguments

  1. destination - (string) the location where to copy the file
  2. createDestinationDirectory - (boolean) create the destination directory (default: true)

Returns

  • (File) this File

Exceptions

  • (DirectoryCreationError) unable to create the destination directory
  • (DirectoryDoesntExistError) the destination directory doesn't exist
  • (CopyError) copy failed

move

Move this file to another location.

Syntax

myObject.move(destination);
myObject.move(destination, createDestinationDirectory);

Arguments

  1. destination - (string) the location where to move the file
  2. createDestinationDirectory - (boolean) create the destination directory (default: true)

Returns

  • (File) this File

Exceptions

  • (DirectoryCreationError) unable to create the destination directory
  • (DirectoryDoesntExistError) the destination directory doesn't exist
  • (MoveRenameError) move failed

rename

This method is an alias of the move method.

remove

Remove this file.

Syntax

myObject.remove();

Returns

  • (File) this File

Exceptions

  • (RemoveError) remove failed
en/code/data/file.1295902935.txt.gz · Last modified: 2021/02/13 11:23 (external edit)