Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.vfs
Interface FileObject

All Known Implementing Classes:
  AbstractFileObject, CompressedFileFileObject, DecoratedFileObject, LocalFile, RamFileObject, SftpFileObject, TarFileObject, UrlFileObject, ZipFileObject

public interface FileObject

Represents a file, and is used to access the content and structure of the file.

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.

#### File Naming

TODO - write this.

#### Reading and Writing a File

Reading and writing a file, and all other operations on the file's content, is done using the `FileContent` object returned by `getContent()`.

#### Creating and Deleting a File

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)`.

#### Finding Files

Other files in the same file system as this file can be found using:

- `resolveFile(java.lang.String, org.apache.commons.vfs.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`.

Version:
  $Revision: 483899 $ $Date: 2006-12-08 10:47:09 +0100 (Fr, 08 Dez 2006) $
Author:
  Adam Murdoch
See Also:
  `FileSystemManager`, `FileContent`, `FileName`

Method Summary
`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 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.

Method Detail

### getName

    public FileName getName()

  Returns the name of this file.

### getURL

    public URL getURL()
               throws FileSystemException

  Returns a URL representing this file.

  Throws:
    `FileSystemException`

### exists

    public boolean exists()
                   throws FileSystemException

  Determines if this file exists.

  Returns:
    `true` if this file exists, `false` if not.
  Throws:
    `FileSystemException` - On error determining if this file exists.

### isHidden

    public boolean isHidden()
                     throws FileSystemException

  Determines if this file is hidden.

  Returns:
    `true` if this file is hidden, `false` if not.
  Throws:
    `FileSystemException` - On error determining if this file exists.

### isReadable

    public boolean isReadable()
                       throws FileSystemException

  Determines if this file can be read.

  Returns:
    `true` if this file is readable, `false` if not.
  Throws:
    `FileSystemException` - On error determining if this file exists.

### isWriteable

    public boolean isWriteable()
                        throws FileSystemException

  Determines if this file can be written to.

  Returns:
    `true` if this file is writeable, `false` if not.
  Throws:
    `FileSystemException` - On error determining if this file exists.

### getType

    public FileType getType()
                     throws FileSystemException

  Returns this file's type.

  Returns:
    One of the `FileType` constants. Never returns null.
  Throws:
    `FileSystemException` - On error determining the file's type.

### getParent

    public FileObject getParent()
                         throws FileSystemException

  Returns the folder that contains this file.

  Returns:
    The folder that contains this file. Returns null if this file is the root of a file system.
  Throws:
    `FileSystemException` - On error finding the file's parent.

### getFileSystem

    public FileSystem getFileSystem()

  Returns the file system that contains this file.

  Returns:
    The file system.

### getChildren

    public FileObject[] getChildren()
                             throws FileSystemException

  Lists the children of this file.

  Returns:
    An array containing the children of this file. The array is unordered. If the file does not have any children, a zero-length array is returned. This method never returns null.
  Throws:
    `FileSystemException` - If this file does not exist, or is not a folder, or on error listing this file's children.

### getChild

    public FileObject getChild(String name)
                        throws FileSystemException

  Returns a child of this file. Note that this method returns `null` when the child does not exist. This differs from `resolveFile( String, NameScope)` which never returns null.

  Parameters:
    `name` - The name of the child.
  Returns:
    The child, or null if there is no such child.
  Throws:
    `FileSystemException` - If this file does not exist, or is not a folder, or on error determining this file's children.

### resolveFile

    public FileObject resolveFile(String name,
                                  NameScope scope)
                           throws FileSystemException

  Finds a file, relative to this file. Refer to `NameScope` for a description of how names are resolved in the different scopes.

  Parameters:
    `name` - The name to resolve.
  Returns:
    The file.
  Throws:
    `FileSystemException` - On error parsing the path, or on error finding the file.

### resolveFile

    public FileObject resolveFile(String path)
                           throws FileSystemException

  Finds a file, relative to this file. Equivalent to calling `resolveFile( path, NameScope.FILE_SYSTEM )`.

  Parameters:
    `path` - The path of the file to locate. Can either be a relative path or an absolute path.
  Returns:
    The file.
  Throws:
    `FileSystemException` - On error parsing the path, or on error finding the file.

### findFiles

    public FileObject[] findFiles(FileSelector selector)
                           throws FileSystemException

  Finds the set of matching descendents of this file, in depthwise order.

  Parameters:
    `selector` - The selector to use to select matching files.
  Returns:
    The matching files. The files are returned in depthwise order (that is, a child appears in the list before its parent).
  Throws:
    `FileSystemException`

### findFiles

    public void findFiles(FileSelector selector,
                          boolean depthwise,
                          List selected)
                   throws FileSystemException

  Finds the set of matching descendents of this file.

  Parameters:
    `selector` - the selector used to determine if the file should be selected
    `depthwise` - controls the ordering in the list. e.g. deepest first
    `selected` - container for selected files. list needs not to be empty.
  Throws:
    `FileSystemException`

### delete

    public boolean delete()
                   throws FileSystemException

  Deletes this file. Does nothing if this file does not exist of if it is a folder that has children. Does not delete any descendents of this file, use `delete(FileSelector)` for that.

  Returns:
    true if this object has been deleted
  Throws:
    `FileSystemException` - If this file is a non-empty folder, or if this file is read-only, or on error deleteing this file.

### delete

    public int delete(FileSelector selector)
               throws FileSystemException

  Deletes all descendents of this file that match a selector. Does nothing if this file does not exist.

  This method is not transactional. If it fails and throws an exception, this file will potentially only be partially deleted.

  Parameters:
    `selector` - The selector to use to select which files to delete.
  Returns:
    the number of deleted objects
  Throws:
    `FileSystemException` - If this file or one of its descendents is read-only, or on error deleting this file or one of its descendents.

### createFolder

    public void createFolder()
                      throws FileSystemException

  Creates this folder, if it does not exist. Also creates any ancestor folders which do not exist. This method does nothing if the folder already exists.

  Throws:
    `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.

### createFile

    public void createFile()
                    throws FileSystemException

  Creates this file, if it does not exist. Also creates any ancestor folders which do not exist. This method does nothing if the file already exists and is a file.

  Throws:
    `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.

### copyFrom

    public void copyFrom(FileObject srcFile,
                         FileSelector selector)
                  throws FileSystemException

  Copies another file, and all its descendents, to this file.

  If this file does not exist, it is created. Its parent folder is also created, if necessary. If this file does exist, it is deleted first.

  This method is not transactional. If it fails and throws an exception, this file will potentially only be partially copied.

  Parameters:
    `srcFile` - The source file to copy.
    `selector` - The selector to use to select which files to copy.
  Throws:
    `FileSystemException` - If this file is read-only, or if the source file does not exist, or on error copying the file.

### moveTo

    public void moveTo(FileObject destFile)
                throws FileSystemException

  Move this file.

  If the destFile exists, it is deleted first

  Parameters:
    `destFile` - the New filename.
  Throws:
    `FileSystemException` - If this file is read-only, or if the source file does not exist, or on error copying the file.

### canRenameTo

    public boolean canRenameTo(FileObject newfile)

  Queries the file if it is possible to rename it to newfile.

  Parameters:
    `newfile` - the new file(-name)
  Returns:
    true it this is the case

### getContent

    public FileContent getContent()
                           throws FileSystemException

  Returns this file's content. The `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.

  Returns:
    This file's content.
  Throws:
    `FileSystemException` - On error getting this file's content.

### close

    public void close()
               throws FileSystemException

  Closes this file, and its content. This method is a hint to the implementation that it can release any resources associated with the file.

  The file object can continue to be used after this method is called.

  Throws:
    `FileSystemException` - On error closing the file.
  See Also:
    `FileContent.close()`

### refresh

    public void refresh()
                 throws FileSystemException

  This will prepare the fileObject to get resynchronized with the underlaying filesystem if required

  Throws:
    `FileSystemException`

### isAttached

    public boolean isAttached()

  check if the fileObject is attaced

### isContentOpen

    public boolean isContentOpen()

  check if someone reads/write to this file

### getFileOperations

    public FileOperations getFileOperations()
                                     throws FileSystemException

  Returns:
    FileOperations interface that provides access to the operations API.
  Throws:
    `FileSystemException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2006 The Apache Software Foundation. All Rights Reserved.