Class File
- All Implemented Interfaces:
DataStreamProvider,IIvyDataObject,Serializable,Cloneable
- See Also:
- API:
- This is a public API.
-
Constructor Summary
ConstructorsConstructorDescriptionFile()Creates a new File which points to the application's persistent file area (i.e. the created file will be a directory).Creates a new persistent File with the given relative path.Creates a new File with the given relative path. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanRead()Tests whether this file is readable.booleancanWrite()Tests whether this file can be modified.clone()Clones the object (shallow clone).voidCopies this file to a new location.voidCopies this file to a new location.booleanAtomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.Creates and returns a copy of this object.booleandelete()Deletes this file or directory.booleanbooleanexists()Tests whether the file or directory denoted by this file object exists.booleanForcedly deletes this file or directory (even if it's not empty).Returns the absolute (and normalized) path of this file object.getName()Returns the name of the file or directory denoted by this file object.Returns the path of the parent file of this file.Returns the parent file of this file.getPath()Returns the relative path of this file object.inthashCode()booleanTrue if the file denoted by this object is a directory.booleanisFile()Tests whether the file denoted by this object is a normal file.booleanReturns true, if this is a temporary file.Returns the time that the file was last modified.longReturns the time that the file was last modified.list()Returns a list of strings naming the files and directories in the directory denoted by this ivy file.Returns a list of ivy files denoting the files in the directory denoted by this ivy file.makePersistent(boolean overwrite) Makes a temporary file persistent.booleanmkdir()Creates the directory named by this aivy file, including any necessary but nonexistent parent directories.Moves this file to the file in the argument.Moves this file to the file specified by the path in the argument.read()Reads the file content and returns it as aStringwith the default encoding.Reads the file content and returns it as aString.Reads the file content and returns it as aBinary.Renames a file in the same directory.toString()voidWrites the givenStringin a file with the default encoding.voidWrites the givenStringin a file with a given encoding.voidwriteBinary(Binary content) Writes the givenBinaryin a file.
-
Constructor Details
-
File
Creates a new File which points to the application's persistent file area (i.e. the created file will be a directory). This has the same effect as creating a file withnew File("", false).- Throws:
IOException- if the file can not be created- API:
- This public API is available in Java.
-
File
Creates a new persistent File with the given relative path. The location of the file is relative to the application's persistent file area. This has the same effect as creating a file withnew File(path,false).- Parameters:
path- a relative path- Throws:
IOException- if path is not valid (e.g. absolute)- API:
- This public API is available in Java.
-
File
Creates a new File with the given relative path. The file will be either persistent or temporary, depending on the value of thetemporaryargument. The location of the file will be relative to the application's persistent or temporary file area, respectively.- Parameters:
path- a relative pathtemporary- iftruethen a temporary file will be created, otherwise a persistent file will be created- Throws:
IOException- if path is not valid (e.g. absolute)- API:
- This public API is available in Java.
-
-
Method Details
-
getJavaFile
- Returns:
- java file
- API:
- This public API is available in Java.
-
getName
Returns the name of the file or directory denoted 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.- Returns:
- name of the file or directory
- API:
- This public API is available in Java.
-
getParent
Returns the path of the parent file of this file. If this file is the base directory (i.e. no parents exist), then the parent path will be equal to the path of this file.- Returns:
- The path of the parent of this file (or the path of this file, if no parent exists).
- API:
- This public API is available in Java.
-
getParentFile
Returns the parent file of this file. If this file is the base directory (i.e. no parents exist), then the parent file will be equal to this file.- Returns:
- The parent of this file (or this file, if no parent exists).
- Throws:
IOException- API:
- This public API is available in Java.
-
getPath
Returns the relative path of this file object. The returned path is always relative to the active file area (i.e. session file area, if file is temporary or application file area if file is persistent).- Returns:
- relative file path
- API:
- This public API is available in Java.
-
getAbsolutePath
Returns the absolute (and normalized) path of this file object.- Returns:
- absolute path
- API:
- This public API is available in Java.
-
exists
public boolean exists()Tests whether the file or directory denoted by this file object exists.- Returns:
- true if file exists otherwise false
- API:
- This public API is available in Java.
-
isFile
public boolean isFile()Tests whether the file denoted by this 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 IvyScript is guaranteed to be a normal file.- Returns:
- true if this is file otherwise false
- API:
- This public API is available in Java.
-
isDirectory
public boolean isDirectory()True if the file denoted by this object is a directory.- Returns:
- true if this is a directory otherwise false
- API:
- This public API is available in Java.
-
list
Returns a list of strings naming the files and directories in the directory denoted by this ivy file.If this ivy file does not denote a directory, then this method returns
null. Otherwise a list of strings is returned, one for each file or directory in the directory. Names denoting the directory itself and the directory's parent directory are not included in the result. Each string is a file name rather than a complete path.There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
- Returns:
- An array of strings naming the files and directories in the
directory denoted by this ivy file. The array will be
empty if the directory is empty. Returns
nullif this ivy file does not denote a directory, or if an I/O error occurs. - API:
- This public API is available in Java.
-
listFiles
Returns a list of ivy files denoting the files in the directory denoted by this ivy file.If this ivy file does not denote a directory, then this method returns
null. Otherwise a list ofFileobjects is returned, one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. If this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative.There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
- Returns:
- A list of abstract pathnames denoting the files and
directories in the directory denoted by this abstract
pathname. The list will be empty if the directory is
empty. Returns
nullif this ivy file does not denote a directory, or if an I/O error occurs. - Throws:
IOException- API:
- This public API is available in Java.
-
canRead
public boolean canRead()Tests whether this file is readable.- Returns:
trueif and only if this file exists and can be read;falseotherwise- API:
- This public API is available in Java.
-
canWrite
public boolean canWrite()Tests whether this file can be modified.- Returns:
trueif and only if the file exists and can be modified;falseotherwise.- API:
- This public API is available in Java.
-
mkdir
public boolean mkdir()Creates the directory named by this aivy file, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.- Returns:
trueif and only if the directory was created, along with all necessary parent directories;falseotherwise- API:
- This public API is available in Java.
-
createNewFile
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.- Returns:
trueif the named file does not exist and was successfully created;falseif the named file already exists- Throws:
IOException- If an I/O error occurred- API:
- This public API is available in Java.
-
delete
public boolean delete()Deletes this file or directory. If this is a directory, then the directory must be empty in order to be deleted.- Returns:
trueif and only if the file or directory is successfully deleted;falseotherwise- API:
- This public API is available in Java.
-
forceDelete
public boolean forceDelete()Forcedly deletes this file or directory (even if it's not empty). If this is a directory, it is deleted recursively. For files, there is no difference betweendelete()and forceDelete().- Returns:
trueif and only if the file or directory is successfully deleted;falseotherwise- API:
- This public API is available in Java.
-
rename
Renames a file in the same directory.- Parameters:
newName- A simple file name.override-- Returns:
- The new file if renaming is successful; just this file is returned if renaming is not possible.
- Throws:
IOException- if the newFile exists and override is not allowed.- API:
- This public API is available in Java.
-
move
Moves this file to the file specified by the path in the argument.The destination file will always be a persistent file independent of the status (temporary, persistent) of the source file.
Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic.
- Parameters:
newPath- The new destinationoverride- Whether an already existing file may be overwritten.- Returns:
- The new file if moving is successful; just this file is returned if moving is not possible.
- Throws:
SecurityException- If a security manager exists and itsmethod denies write access to either the old or new pathnamesSecurityManager.checkWrite(java.lang.String)NullPointerException- If parameternewPathisnullIOException- if the newFile exists and override is not allowed.- API:
- This public API is available in Java.
-
move
Moves this file to the file in the argument.Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic.
- Parameters:
newFile- The new destinationoverride- Whether an already existing file may be overwritten.- Returns:
- The new file if moving is successful; just this file is returned if moving is not possible.
- Throws:
SecurityException- If a security manager exists and itsmethod denies write access to either the old or new pathnamesSecurityManager.checkWrite(java.lang.String)NullPointerException- If parameternewPathisnullIOException- if the newFile exists and override is not allowed.- API:
- This public API is available in Java.
-
copy
Copies this file to a new location.The destination file will always be a persistent file independent of the status (temporary, persistent) of the source file.
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist.
- Parameters:
newPath- the path of the new file, must not be null.override- Whether it is allowed to override an existing file.preserveFileDate- true if the file date of the copy should be the same as the original- Throws:
NullPointerException- if source or destination is nullIOException- if source or destination is invalidIOException- if an IO error occurs during copying- API:
- This public API is available in Java.
-
copy
Copies this file to a new location.This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist.
- Parameters:
newFile- the new location, must not be null.override- Whether it is allowed to override an existing file.preserveFileDate- true if the file date of the copy should be the same as the original- Throws:
NullPointerException- if source or destination is nullIOException- if source or destination is invalidIOException- if an IO error occurs during copying- API:
- This public API is available in Java.
-
isTemporary
public boolean isTemporary()Returns true, if this is a temporary file.- Returns:
trueif temporary,falseif persistent- API:
- This public API is available in Java.
-
makePersistent
Makes a temporary file persistent. This method has no effect, if the file is already persistent (i.e. ifisTemporary()==false).If there's already a persistent file with the name of this temporary file then the existing file will either be overwritten or renamed, depending on the value of the
overwriteparameter.If
overwrite == falsethen this file will be renamed to an unused name, i.e. the resulting persistent file's name may be different after themakePersistentoperation. The new name will be something like fileName{Number}.ext.When persisted, a file is moved from a temporary file space into a persistent file space. The old (temporary) file will no longer exist after a successful
makePersistentoperation.- Parameters:
overwrite- iftrueany existing persistent file with same name will be overwritten, iffalsethen this file will be renamed after the operation- Returns:
- The new file, persistent (with possibly different name).
- Throws:
IOException- if operation fails.- See Also:
- API:
- This public API is available in Java.
-
read
Reads the file content and returns it as aStringwith the default encoding.- Returns:
- file content or null
- Throws:
IOException- if the file can not be read- API:
- This public API is available in Java.
-
read
Reads the file content and returns it as aString.- Parameters:
encoding- file encoding- Returns:
- file content or null
- Throws:
IOException- if the file can not be read- API:
- This public API is available in Java.
-
readBinary
Reads the file content and returns it as aBinary.- Returns:
- file content or null
- Throws:
IOException- if the file can not be read- API:
- This public API is available in Java.
-
write
Writes the givenStringin a file with the default encoding.- Parameters:
content- file content- Throws:
IOException- if the file can not be written- API:
- This public API is available in Java.
-
write
Writes the givenStringin a file with a given encoding.- Parameters:
content- file contentencoding- encoding- Throws:
IOException- if the file can not be written- API:
- This public API is available in Java.
-
writeBinary
Writes the givenBinaryin a file.- Parameters:
content- file content- Throws:
IOException- if the file can not be written- API:
- This public API is available in Java.
-
equals
- API:
- This public API is available in Java.
-
hashCode
public int hashCode()- API:
- This public API is available in Java.
-
lastModifiedMillis
public long lastModifiedMillis()Returns the time that the file was last modified.- Returns:
- A
longvalue representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or0Lif the file does not exist or if an I/O error occurs - API:
- This public API is available in Java.
-
lastModified
Returns the time that the file was last modified.- Returns:
- last modification timestamp or null.
- API:
- This public API is available in Java.
-
clone
Description copied from interface:IIvyDataObjectClones the object (shallow clone).- Specified by:
clonein interfaceIIvyDataObject- Returns:
- A shallow clone.
- API:
- This public API is available in Java.
-
deepClone
Creates and returns a copy of this object.- Specified by:
deepClonein interfaceIIvyDataObject- Returns:
- new copy of this object
- API:
- This public API is available in Java.
-
toString
- API:
- This public API is available in Java.
-