public interface FileObject
Files are arranged in a hierarchy. Each hierachy forms a file system. A file system represents things like a local OS file system, a windows share, an HTTP server, or the contents of a Zip file.
There are two types of files: Folders, which contain other files, and normal files, which contain data, or content. A folder may not have any content, and a normal file cannot contain other files.
TODO - write this.
Reading and writing a file, and all other operations on the file's
content, is done using the FileContent
object returned
by getContent()
.
A file is created using either createFolder()
, createFile()
,
or by writing to the file using one of the FileContent
methods.
A file is deleted using delete()
. Recursive deletion can be
done using delete(FileSelector)
.
Other files in the same file system as this file can be found using:
resolveFile(java.lang.String, org.apache.commons.vfs2.NameScope)
to find another file relative to this file.
getChildren()
and getChild(java.lang.String)
to find the children of this file.
getParent()
to find the folder containing this file.
getFileSystem()
to find another file in the same file system.
To find files in another file system, use a FileSystemManager
.
FileSystemManager
,
FileContent
,
FileName
Modifier and Type | Method and Description |
---|---|
boolean |
canRenameTo(FileObject newfile)
Queries the file if it is possible to rename it to newfile.
|
void |
close()
Closes this file, and its content.
|
void |
copyFrom(FileObject srcFile,
FileSelector selector)
Copies another file, and all its descendents, to this file.
|
void |
createFile()
Creates this file, if it does not exist.
|
void |
createFolder()
Creates this folder, if it does not exist.
|
boolean |
delete()
Deletes this file.
|
int |
delete(FileSelector selector)
Deletes all descendents of this file that match a selector.
|
boolean |
exists()
Determines if this file exists.
|
FileObject[] |
findFiles(FileSelector selector)
Finds the set of matching descendents of this file, in depthwise order.
|
void |
findFiles(FileSelector selector,
boolean depthwise,
List<FileObject> selected)
Finds the set of matching descendents of this file.
|
FileObject |
getChild(String name)
Returns a child of this file.
|
FileObject[] |
getChildren()
Lists the children of this file.
|
FileContent |
getContent()
Returns this file's content.
|
FileOperations |
getFileOperations() |
FileSystem |
getFileSystem()
Returns the file system that contains this file.
|
FileName |
getName()
Returns the name of this file.
|
FileObject |
getParent()
Returns the folder that contains this file.
|
FileType |
getType()
Returns this file's type.
|
URL |
getURL()
Returns a URL representing this file.
|
boolean |
isAttached()
check if the fileObject is attaced.
|
boolean |
isContentOpen()
check if someone reads/write to this file.
|
boolean |
isHidden()
Determines if this file is hidden.
|
boolean |
isReadable()
Determines if this file can be read.
|
boolean |
isWriteable()
Determines if this file can be written to.
|
void |
moveTo(FileObject destFile)
Move this file.
|
void |
refresh()
This will prepare the fileObject to get resynchronized with the underlaying filesystem if required.
|
FileObject |
resolveFile(String path)
Finds a file, relative to this file.
|
FileObject |
resolveFile(String name,
NameScope scope)
Finds a file, relative to this file.
|
FileName getName()
URL getURL() throws FileSystemException
FileSystemException
- if an error occurs.boolean exists() throws FileSystemException
true
if this file exists, false
if not.FileSystemException
- On error determining if this file exists.boolean isHidden() throws FileSystemException
true
if this file is hidden, false
if not.FileSystemException
- On error determining if this file exists.boolean isReadable() throws FileSystemException
true
if this file is readable, false
if not.FileSystemException
- On error determining if this file exists.boolean isWriteable() throws FileSystemException
true
if this file is writeable, false
if not.FileSystemException
- On error determining if this file exists.FileType getType() throws FileSystemException
FileType
constants. Never returns null.FileSystemException
- On error determining the file's type.FileObject getParent() throws FileSystemException
FileSystemException
- On error finding the file's parent.FileSystem getFileSystem()
FileObject[] getChildren() throws FileSystemException
FileSystemException
- If this file does not exist, or is not a folder, or on error
listing this file's children.FileObject getChild(String name) throws FileSystemException
null
when the child does not exist. This differs from
resolveFile( String, NameScope)
which never returns null.name
- The name of the child.FileSystemException
- If this file does not exist, or is not a folder, or on error
determining this file's children.FileObject resolveFile(String name, NameScope scope) throws FileSystemException
NameScope
for a description of how names are resolved in the different scopes.name
- The name to resolve.scope
- the NameScope for the file.FileSystemException
- On error parsing the path, or on error finding the file.FileObject resolveFile(String path) throws FileSystemException
resolveFile( path, NameScope.FILE_SYSTEM )
.path
- The path of the file to locate. Can either be a relative
path or an absolute path.FileSystemException
- On error parsing the path, or on error finding the file.FileObject[] findFiles(FileSelector selector) throws FileSystemException
selector
- The selector to use to select matching files.FileSystemException
- if an error occurs.void findFiles(FileSelector selector, boolean depthwise, List<FileObject> selected) throws FileSystemException
selector
- the selector used to determine if the file should be selecteddepthwise
- controls the ordering in the list. e.g. deepest firstselected
- container for selected files. list needs not to be empty.FileSystemException
- if an error occurs.boolean delete() throws FileSystemException
delete(FileSelector)
for that.FileSystemException
- If this file is a non-empty folder, or if this file is read-only,
or on error deleteing this file.int delete(FileSelector selector) throws FileSystemException
This method is not transactional. If it fails and throws an exception, this file will potentially only be partially deleted.
selector
- The selector to use to select which files to delete.FileSystemException
- If this file or one of its descendents is read-only, or on error
deleting this file or one of its descendents.void createFolder() throws FileSystemException
FileSystemException
- If the folder already exists with the wrong type, or the parent
folder is read-only, or on error creating this folder or one of
its ancestors.void createFile() throws FileSystemException
FileSystemException
- If the file already exists with the wrong type, or the parent
folder is read-only, or on error creating this file or one of
its ancestors.void copyFrom(FileObject srcFile, FileSelector selector) throws FileSystemException
This method is not transactional. If it fails and throws an exception, this file will potentially only be partially copied.
srcFile
- The source file to copy.selector
- The selector to use to select which files to copy.FileSystemException
- If this file is read-only, or if the source file does not exist,
or on error copying the file.void moveTo(FileObject destFile) throws FileSystemException
If the destFile exists, it is deleted first
destFile
- the New filename.FileSystemException
- If this file is read-only, or if the source file does not exist,
or on error copying the file.boolean canRenameTo(FileObject newfile)
newfile
- the new file(-name)FileContent getContent() throws FileSystemException
FileContent
returned by this
method can be used to read and write the content of the file.
This method can be called if the file does not exist, and
the returned FileContent
can be used to create the file
by writing its content.
FileSystemException
- On error getting this file's content.void close() throws FileSystemException
The file object can continue to be used after this method is called.
FileSystemException
- On error closing the file.FileContent.close()
void refresh() throws FileSystemException
FileSystemException
- if an error occurs.boolean isAttached()
boolean isContentOpen()
FileOperations getFileOperations() throws FileSystemException
FileSystemException
- if an error occurs.Copyright © 2002-2016 The Apache Software Foundation. All Rights Reserved.