Libraries anvil io File

class File
extends anvil.lang.object
A representation of file and directory pathnames.

Constructor
File(string file)
File(string parent, string child)
File(File parent, string child)
Creates new File object.
Parameters file -  Path to file
parent -  Base path to merged with child
child -  Child path to merged with parent


Methods

boolean canRead()
Checks if the contents of file can be read.

boolean canWrite()
Checks if the contents of file can be written.

File close()
Closes this random access file stream and releases any system resources associated with the stream. A closed file cannot perform input or output operations.
Throws IOError -  If an I/O error occurs

boolean createNewFile()
Creates the a new, empty file if and only if the file with this name does not yeat exist.
Returns true if the named file does not exist and was successfully created; false if the named file already exists
Throws IOError -  If an I/O error occurred

boolean exists()
Checks if the file actually exists.

File getAbsoluteFile()
Returns the absolute path as file.

string getAbsolutePath()
Returns the absolute path.

File getCanonicalFile()
Returns the canonical path as File.

string getCanonicalPath()
Returns the canonical path.

string getName()
Returns the name of file pointed by this File instance.

string getParent()
Returns the path of parent file pointed by this File instance.

File getParentFile()
Returns the parent file pointed by this File instance.

string getPath()
Returns the path of file pointed by this File instance.

int getPos()
Returns the current file position.
Throws IOError -  If an I/O error occurs

boolean isAbsolute()
Tests if the file represented by this File object is an absolute pathname.

boolean isDirectory()
Checks if the file is directory.

boolean isFile()
Checks if the file is regular file.

boolean isHidden()
Checks is the file is hidden.

int lastModified()
Gets the timestamp of last modification (milliseconds since 1.1.1970).

int length()
Return the length of file.
Throws IOError -  If an I/O error occurs

array list()
Returns an array of strings naming the files and directories in the directory denoted by this pathname.
Returns array of strings

array listFiles()
Returns an array of File objects describing the files and directories in the directory denoted by this pathname.
Returns array of Files containing files and directories, or null if this File does not point to directory.

boolean mkdir()
Creates the last part of path.
Returns true if and only if the directory was created; false otherwise

boolean mkdirs()
Creates the full path.
Returns true if and only if all directories was created; false otherwise

File open()
File open(string mode)
Opens file for reading (mode is "r") or writing (mode is "w"). If the mode is "rw" and it does not exists, attempt is made to create it.
Throws IOError -  If an I/O error occurs

InputStream openInput()
Opens an input stream to file.
Throws IOError -  If an I/O error occurs

OutputStream openOutput()
Opens an output stream to file.
Throws IOError -  If an I/O error occurs

int read()
Reads next byte from file
string read(int amount)
Reads given amount of bytes from file.
Parameters amout -  Amount of bytes to read
Returns string, or int, or null if end of stream encountered (and no bytes could not be read before it).
Throws IOError -  If an I/O error occurs

int readBinary(binary bin)
int readBinary(binary bin, int offset)
int readBinary(binary bin, int offset, int length)
Reads from file to given binary.
Parameters bin -  The binary into which the data is read
offset -  The start offset of the data
length -  The maximum number of bytes to read
Returns the amount of bytes read, or -1 if there is no more data because the end of file has been reached.
Throws IOError -  If an I/O error occurs

object readData()
Reads and returns next serialized data from file.
Throws CorruptedSerialization -  If serialized data is correupted
IOError -  If an I/O error occurs

string readLine()
Reads a single line from file.
Returns line in string, or null if an error occured or end of stream encountered (and no bytes could not be read before it).
Throws IOError -  If an I/O error occurs

list readLines()
Reads as many lines as possible from this file
list readLines(int maxLines)
Reads upto given amount of lines from this file
Parameters maxLines -  Maximum number of lines to read
Returns List of strings
Throws IOError -  If an I/O error occurs

boolean remove()
Removes the file. If this pathname denotes a directory, then the directory must be empty in order to be deleted.
Returns true if and only if the file or directory is successfully remove; false otherwise

File removeOnExit()
Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.

boolean renameTo(string newName)
boolean renameTo(File newName)
Renames the file.
Returns true if and only if the renaming succeeded; false otherwise

File seek(int pos)
Seeks file pointer to new position.
Parameters pos -  the offset position, measured in bytes from the beginning of the file,
Throws IOError -  If an I/O error occurs

boolean setLastModified(int timestamp)
Sets last modification timestamp.

int setLength(int newLength)
Sets the length of file to 'newLength'. If 'newLength' is greater than the current length, contents of extended section is undefined.
Throws IOError -  If an I/O error occurs

boolean setReadOnly()
Sets the file readonly.

int skip(int amount)
Skips given amount of bytes.
Parameters amount -  Amount of bytes to skip
Returns number of bytes skipped.
Throws IOError -  If an I/O error occurs

File sync()
Attempts to synchronize the changes back to disk.
Throws IOError -  If an I/O error occurs

URL toURL()
Converts path on this File variable to file:// URL.

File write(int byte)
Writes single byte to file
File write(binary bin)
Writes bytes to file
File write(string text)
Writes text to file
Throws IOError -  If an I/O error occurs

File writeBinary(binary bin)
File writeBinary(binary bin, int offset, int length)
Writes the contents of binary to file.
Parameters bin -  The binary from which the data is written
offset -  The start offset of the data
length -  The number of bytes to write
Throws IOError -  If an I/O error occurs

File writeData(object data, ...)
Serializes parameters to file.
Parameters data -  Data to serialize
Throws IOError -  If an I/O error occurs


Operators

iterator * InstanceOfFile
If this file points directory, return iterator of files in directory, otherwise returns iterator of lines in file.