public class File extends Object implements IIvyDataObject
Constructor and Description |
---|
File()
Creates a new File which points to the application's persistent
file area (i.e.
|
File(String path)
Creates a new persistent File with the given relative path.
|
File(String path,
boolean temporary)
Creates a new File with the given relative path.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canRead()
Tests whether this file is readable.
|
boolean |
canWrite()
Tests whether this file can be modified.
|
File |
clone()
Creates a clone.
|
void |
copy(File newFile,
boolean override,
boolean preserveFileDate)
Copies this file to a new location.
|
void |
copy(String newPath,
boolean override,
boolean preserveFileDate)
Copies this file to a new location.
|
boolean |
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.
|
File |
deepClone()
Creates a clone; the same as clone().
|
boolean |
delete()
Deletes this file or directory.
|
boolean |
equals(Object another)
Test equaliy of files: two files are equals is the habe the same normalized absolute path.
|
boolean |
exists()
Tests whether the file or directory denoted by this file object exists.
|
boolean |
forceDelete()
Deletes this file or directory.
|
String |
getAbsolutePath()
Returns the absolute (and normalized) path of this file object.
|
File |
getJavaFile() |
String |
getName()
Returns the name of the file or directory denoted by this file object.
|
String |
getParent()
Returns the path of the parent file of this file.
|
File |
getParentFile()
Returns the parent file of this file.
|
String |
getPath()
Returns the relative path of this file object.
|
int |
hashCode()
A Hash for the file.
|
boolean |
isDirectory()
returns true if the file denoted by this object is a directory.
|
boolean |
isFile()
Tests whether the file denoted by this object is a normal
file.
|
boolean |
isTemporary()
Returns true, if this is a temporary file.
|
DateTime |
lastModified()
Returns the time that the file was last modified.
|
long |
lastModifiedMillis()
Returns the time that the file was last modified.
|
List<String> |
list()
Returns a list of strings naming the files and directories in the
directory denoted by this ivy file.
|
List<File> |
listFiles()
Returns a list of ivy files denoting the files in the
directory denoted by this ivy file.
|
File |
makePersistent(boolean overwrite)
Makes a temporary file persistent.
|
boolean |
mkdir()
Creates the directory named by this aivy file, including any
necessary but nonexistent parent directories.
|
File |
move(File newFile,
boolean override)
Moves this file to the file in the argument.
|
File |
move(String newPath,
boolean override)
Moves this file to the file specified by the path in the argument.
|
String |
read()
Reads the file content and returns it as a String;
the default encoding is used.
|
String |
read(String encoding)
Reads the file content and returns it as a String.
|
Binary |
readBinary()
Reads the file content and returns it as a Binary.
|
File |
rename(String newName,
boolean override)
Renames a file in the same directory.
|
String |
toString()
Returns the path of the file.
|
void |
write(String content)
Writes a given String in a file with the default encoding.
|
void |
write(String content,
String encoding)
Writes a given String in a file with a given encoding.
|
void |
writeBinary(Binary content)
Writes a given Binary in a file.
|
public File() throws IOException
new File("",false)
.IOException
public File(String path) throws IOException
new File(path,false)
.path
- a relative pathIOException
- if path is not valid (e.g. absolute)public File(String path, boolean temporary) throws IOException
temporary
argument. The location of the
file will be relative to the application's persistent or temporary
file area, respectively.path
- a relative pathtemporary
- if true
then a temporary file will be created,
otherwise a persistent file will be createdIOException
- if path is not valid (e.g. absolute)public File getJavaFile()
public String getName()
public String getParent()
public File getParentFile() throws IOException
IOException
public String getPath()
public String getAbsolutePath()
public boolean exists()
public boolean isFile()
public boolean isDirectory()
public List<String> list()
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.
null
if
this ivy file does not denote a directory, or if an
I/O error occurs.public List<File> listFiles() throws IOException
If this ivy file does not denote a directory, then this
method returns null
. Otherwise a list of
File
objects 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.
null
if this ivy file
does not denote a directory, or if an I/O error occurs.IOException
public boolean canRead()
true
if and only if this file
exists and can be read; false
otherwisepublic boolean canWrite()
true
if and only if the file exists and can be modified;
false
otherwise.public boolean mkdir()
true
if and only if the directory was created,
along with all necessary parent directories; false
otherwisepublic boolean createNewFile() throws IOException
true
if the named file does not exist and was
successfully created; false
if the named file
already existsIOException
- If an I/O error occurredpublic boolean delete()
true
if and only if the file or directory is
successfully deleted; false
otherwisepublic boolean forceDelete()
true
if and only if the file or directory is
successfully deleted; false
otherwisepublic File rename(String newName, boolean override) throws IOException
newName
- A simple file name.override
- IOException
- if the newFile exists and override is not allowed.public File move(String newPath, boolean override) throws IOException
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.
newPath
- The new destinationoverride
- Whether an already existing file may be overwritten.SecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String)
method denies write access to either the old or new pathnamesNullPointerException
- If parameter newPath
is null
IOException
- if the newFile exists and override is not allowed.public File move(File newFile, boolean override) throws IOException
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.
newFile
- The new destinationoverride
- Whether an already existing file may be overwritten.SecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String)
method denies write access to either the old or new pathnamesNullPointerException
- If parameter newPath
is null
IOException
- if the newFile exists and override is not allowed.public void copy(String newPath, boolean override, boolean preserveFileDate) throws IOException
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.
newPath
- the path of the new file, must not be null.override
- Whether it is allowed to oberride an existing file.preserveFileDate
- true if the file date of the copy
should be the same as the originalNullPointerException
- if source or destination is nullIOException
- if source or destination is invalidIOException
- if an IO error occurs during copyingpublic void copy(File newFile, boolean override, boolean preserveFileDate) throws IOException
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.
newFile
- the new location, must not be null.override
- Whether it is allowed to oberride an existing file.preserveFileDate
- true if the file date of the copy
should be the same as the originalNullPointerException
- if source or destination is nullIOException
- if source or destination is invalidIOException
- if an IO error occurs during copyingpublic boolean isTemporary()
true
if temporary, false
if persistentpublic File makePersistent(boolean overwrite) throws IOException
File.isTemporary()
== 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 overwrite
parameter.
If overwrite == false
then this file will be renamed to
an unused name, i.e. the resulting persistent file's name may be different
after the makePersistent
operation. 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 makePersistent
operation.
overwrite
- if true
any existing persistent file with same name will be overwritten,
if false
then this file will be renamed after the operationIOException
- if operation fails.File.isTemporary()
public String read() throws IOException
IOException
public String read(String encoding) throws IOException
encoding
- The file encoding.IOException
public Binary readBinary() throws IOException
IOException
public void write(String content) throws IOException
content
- The file contentIOException
public void write(String content, String encoding) throws IOException
content
- The file contentencoding
- IOException
public void writeBinary(Binary content) throws IOException
content
- The file contentIOException
public boolean equals(Object another)
public int hashCode()
public long lastModifiedMillis()
long
value 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 occursSecurityException
- If a security manager exists and its SecurityManager.checkRead(java.lang.String)
method denies read access to the filepublic DateTime lastModified()
SecurityException
- If a security manager exists and its SecurityManager.checkRead(java.lang.String)
method denies read access to the filepublic File clone()
clone
in interface IIvyDataObject
clone
in class Object
public File deepClone()
deepClone
in interface IIvyDataObject
Copyright © 2024
AXON IVY AG
All Rights Reserved Documentation was generated
on April 28, 2024