# Class: File

## helma.File(path)

This class represents a local file or directory

## Constructor

#### new File(path)

Constructor for File objects, providing read and write access to the file system.

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | String | as String, can be either absolute or relative to the helma home directory

Source:
  - helma/File.js, line 41

### Methods

#### canRead()

Tests whether the application can read the file represented by this File object.

Source:
  - helma/File.js, line 420

##### Returns:

Boolean true if the file exists and can be read; false otherwise

#### canWrite()

Tests whether the file represented by this File object is writable.

Source:
  - helma/File.js, line 430

##### Returns:

Boolean true if the file exists and can be modified; false otherwise.

#### clearError()

Clears any error message that may otherwise be returned by the error method.

Source:
  - helma/File.js, line 408
See:
  - #error

#### close()

Closes the file represented by this File object.

Source:
  - helma/File.js, line 355

##### Returns:

Boolean

#### eof()

Returns true if the file represented by this File object has been read entirely and the end of file has been reached.

Source:
  - helma/File.js, line 555

##### Returns:

Boolean

#### error()

Contains the last error that occured, if any.

Source:
  - helma/File.js, line 391
See:
  - #clearError

##### Returns:

String

#### exists()

Tests whether the file or directory represented by this File object exists.

Source:
  - helma/File.js, line 169

##### Returns:

Boolean true if the file or directory exists; false otherwise

#### flush()

Purges the content of the file represented by this File object.

Source:
  - helma/File.js, line 330

##### Returns:

Boolean

#### getAbsolutePath()

Returns the absolute pathname string of this file.
If this File object's pathname is already absolute, then the pathname string is simply returned as if by the getPath() method. If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, which is named by the system property user.dir, is returned. Otherwise this pathname is resolved in a system-dependent way. On UNIX systems, a relative pathname is made absolute by resolving it against the current user directory. On Microsoft Windows systems, a relative pathname is made absolute by resolving it against the current directory of the drive named by the pathname, if any; if not, it is resolved against the current user directory.

Source:
  - helma/File.js, line 452

##### Returns:

String The absolute pathname string

#### getLength()

Returns the length of the file represented by this File object.
The return value is unspecified if this pathname denotes a directory.

Source:
  - helma/File.js, line 465

##### Returns:

Number The length, in bytes, of the file, or 0L if the file does not exist

#### getName()

Returns the name of the file or directory represented by this File object.
This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.

Source:
  - helma/File.js, line 94

##### Returns:

String containing the name of the file or directory

#### getParent()

Returns the pathname string of this File object's parent directory.

Source:
  - helma/File.js, line 179

##### Returns:

String containing the pathname of the parent directory

#### getPath()

Returns the pathname string of this File object.
The resulting string uses the default name-separator character to separate the names in the name sequence.

Source:
  - helma/File.js, line 380

##### Returns:

String of this file's pathname

#### hardCopy(dest)

Makes a copy of a file over partitions.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dest` | String | helma.File | as a File object or the String of full path of the new file

Source:
  - helma/File.js, line 680

#### isAbsolute()

Tests whether this File object's pathname is absolute.
The definition of absolute pathname is system dependent. On UNIX systems, a pathname is absolute if its prefix is "/". On Microsoft Windows systems, a pathname is absolute if its prefix is a drive specifier followed by "\\", or if its prefix is "\\".

Source:
  - helma/File.js, line 278

##### Returns:

Boolean if this abstract pathname is absolute, false otherwise

#### isDirectory()

Tests whether the file represented by this File object is a directory.

Source:
  - helma/File.js, line 475

##### Returns:

Boolean true if this File object is a directory and exists; false otherwise

#### isFile()

Tests whether the file represented by this File object is a normal file.
A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.

Source:
  - helma/File.js, line 489

##### Returns:

Boolean true if this File object is a normal file and exists; false otherwise

#### isOpened()

Returns true if the file represented by this File object is currently open.

Source:
  - helma/File.js, line 106

##### Returns:

Boolean

#### lastModified()

Returns the time when the file represented by this File object was last modified.
A number representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs.

Source:
  - helma/File.js, line 503

##### Returns:

Number in milliseconds since 00:00:00 GMT, January 1, 1970

#### list(pattern)

List of all files within the directory represented by this File object.
You may pass a RegExp Pattern to return just files matching this pattern.
Example: var xmlFiles = dir.list(/.*\.xml/);

##### Parameters:

Name | Type | Description
--- | --- | ---
`pattern` | RegExp | as RegExp, optional pattern to test each file name against

Source:
  - helma/File.js, line 307

##### Returns:

Array the list of file names

#### listRecursive(pattern)

Recursivly lists all files below a given directory you may pass a RegExp Pattern to return just files matching this pattern.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pattern` | RegExp | as RegExp, to test each file name against

Source:
  - helma/File.js, line 657

##### Returns:

Array the list of absolute file paths

#### makeDirectory()

Creates the directory represented by this File object.

Source:
  - helma/File.js, line 513

##### Returns:

Boolean true if the directory was created; false otherwise

#### move(dest)

Moves a file to a new destination directory.

##### Parameters:

Name | Type | Description
--- | --- | ---
`dest` | String | as String, the full path of the new file

Source:
  - helma/File.js, line 706

##### Returns:

Boolean true in case file could be moved, false otherwise

#### open(options)

Opens the file represented by this File object. If the file exists, it is used for reading, otherwise it is opened for writing. If the encoding argument is specified, it is used to read or write the file. Otherwise, the platform's default encoding is used.

##### Parameters:

Name | Type | Description
--- | --- | ---

`options`

Object

an optional argument holder object. The following options are supported:

- charset name of encoding to use for reading or writing
- append whether to append to the file if it exists

Source:
  - helma/File.js, line 123

##### Returns:

Boolean true if the operation succeeded

#### readAll()

This methods reads all the lines contained in the file and returns them.

Source:
  - helma/File.js, line 586

##### Returns:

String of all the lines in the file

#### readln()

This methods reads characters until an end of line/file is encountered then returns the string for these characters (without any end of line character).

Source:
  - helma/File.js, line 193

##### Returns:

String of the next unread line in the file

#### remove()

Deletes the file or directory represented by this File object.

Source:
  - helma/File.js, line 288

##### Returns:

Boolean

#### removeDirectory()

This method removes a directory recursively .
DANGER! DANGER! HIGH VOLTAGE! The directory is deleted recursively without any warning or precautious measures.

Source:
  - helma/File.js, line 634

#### renameTo(toFile)

Renames the file represented by this File object.
Whether or not this method can move a file from one filesystem to another is platform-dependent. The return value should always be checked to make sure that the rename operation was successful.

##### Parameters:

Name | Type | Description
--- | --- | ---
`toFile` | FileObject | as FileObject of the new path

Source:
  - helma/File.js, line 532

##### Returns:

true if the renaming succeeded; false otherwise

#### toByteArray()

Returns file as ByteArray.
Useful for passing it to a function instead of an request object.

Source:
  - helma/File.js, line 721

#### write(what)

Appends a string to the file represented by this File object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`what` | String | as String, to be written to the file

Source:
  - helma/File.js, line 235
See:
  - #writeln

##### Returns:

Boolean

#### writeln(what)

Appends a string with a platform specific end of line to the file represented by this File object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`what` | String | as String, to be written to the file

Source:
  - helma/File.js, line 259
See:
  - #write

##### Returns:

Boolean