Default properties and methods of
the File prototype.
Constructor for File objects, providing read and write access to the file system.
Example:
Example:
var fileOrDir = new File('static/test.txt');parameters
| String | filepath | as String |
methods
- getName()
- write(data)
- remove()
- list(pattern)
- flush()
- writeln(data)
- close()
- getPath()
- open()
- error(Object)
- canRead()
- canWrite()
- exists()
- isFile()
- mkdir()
- renameTo(dest)
- eof()
- isOpened()
- readln()
- readAll()
see
Methods
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.
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.
returns
| String containing the name of the file or directory |
Returns the pathname string of this File object's parent directory.
returns
| String containing the pathname of the parent directory |
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 "\\".
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 "\\".
returns
| Boolean if this abstract pathname is absolute, false otherwise |
Appends a string to the file represented by this File object.
parameters
| String | data | as String, to be written to the file |
returns
| Boolean |
see
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:
You may pass a RegExp Pattern to return just files matching this pattern.
Example:
var xmlFiles = dir.list(/.*\.xml/);
parameters
| RegExp | pattern | as RegExp, optional pattern to test each file name against |
returns
| Array the list of file names |
Appends a string with a platform specific end of
line to the file represented by this File object.
parameters
| String | data | as String, to be written to the file |
returns
| Boolean |
see
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.
The resulting string uses the default name-separator character to separate the names in the name sequence.
returns
| String of this file's pathname |
Contains the last error that occured, if any.
parameters
| Object |
returns
| String |
see
Tests whether the application can read the file
represented by this File object.
returns
| Boolean true if the file exists and can be read; false otherwise |
Tests whether the file represented by this File object is writable.
returns
| Boolean true if the file exists and can be modified; false otherwise. |
Tests whether the file or directory represented by this File object exists.
returns
| Boolean true if the file or directory exists; false otherwise |
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.
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.
returns
| String The absolute pathname string |
Returns the length of the file represented by this File object.
The return value is unspecified if this pathname denotes a directory.
The return value is unspecified if this pathname denotes a directory.
returns
| Number The length, in bytes, of the file, or 0L if the file does not exist |
Tests whether the file represented by this File object is a directory.
returns
| Boolean true if this File object is a directory and exists; false otherwise |
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.
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.
returns
| Boolean true if this File object is a normal file and exists; false otherwise |
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.
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.
returns
| Number in milliseconds since 00:00:00 GMT, January 1, 1970 |
Creates the directory represented by this File object.
returns
| Boolean true if the directory was created; false otherwise |
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.
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
| FileObject | dest | as FileObject of the new path |
returns
| true if the renaming succeeded; false otherwise |
Returns true if the file represented by this File object
has been read entirely and the end of file has been reached.
returns
| Boolean |
Returns true if the file represented by this File object
is currently open.
returns
| Boolean |
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).
returns
| String of the next unread line in the file |
Clears any error message that may otherwise be returned by the error method.
see
This methods reads all the lines contained in the
file and returns them.
returns
| String of all the lines in the file |
