org.modeshape.common.util

## Class FileUtil

- java.lang.Object
- - org.modeshape.common.util.FileUtil

-     @Immutable
      public class FileUtil
      extends Object

  A set of utilities for working with files and directories.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FileUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static URL` | `convertFileToURL(String filePath)` Utility to convert `File` to `URL`.
    `static int` | `copy(File sourceFileOrDirectory, File destinationFileOrDirectory)` Copy the source file system structure into the supplied target location.
    `static int` | `copy(File sourceFileOrDirectory, File destinationFileOrDirectory, FilenameFilter exclusionFilter)` Copy the source file system structure into the supplied target location.
    `static boolean` | `delete(File fileOrDirectory)` Delete the file or directory given by the supplied reference.
    `static boolean` | `delete(String path)` Delete the file or directory at the supplied path.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FileUtil

          public FileUtil()

  - ### Method Detail

    - #### delete

          public static boolean delete(String path)

      Delete the file or directory at the supplied path. This method works on a directory that is not empty, unlike the `File.delete()` method.
      Parameters:
        `path` - the path to the file or directory that is to be deleted
      Returns:
        true if the file or directory at the supplied path existed and was successfully deleted, or false otherwise

    - #### delete

          public static boolean delete(File fileOrDirectory)

      Delete the file or directory given by the supplied reference. This method works on a directory that is not empty, unlike the `File.delete()` method.
      Parameters:
        `fileOrDirectory` - the reference to the Java File object that is to be deleted
      Returns:
        true if the supplied file or directory existed and was successfully deleted, or false otherwise

    - #### copy

          public static int copy(File sourceFileOrDirectory,
                 File destinationFileOrDirectory)
                          throws IOException

      Copy the source file system structure into the supplied target location. If the source is a file, the destination will be created as a file; if the source is a directory, the destination will be created as a directory.
      Parameters:
        `sourceFileOrDirectory` - the file or directory whose contents are to be copied into the target location
        `destinationFileOrDirectory` - the location where the copy is to be placed; does not need to exist, but if it does its type must match that of `src`
      Returns:
        the number of files (not directories) that were copied
      Throws:
        `IllegalArgumentException` - if the `src` or `dest` references are null
        `IOException`

    - #### copy

          public static int copy(File sourceFileOrDirectory,
                 File destinationFileOrDirectory,
                 FilenameFilter exclusionFilter)
                          throws IOException

      Copy the source file system structure into the supplied target location. If the source is a file, the destination will be created as a file; if the source is a directory, the destination will be created as a directory.
      Parameters:
        `sourceFileOrDirectory` - the file or directory whose contents are to be copied into the target location
        `destinationFileOrDirectory` - the location where the copy is to be placed; does not need to exist, but if it does its type must match that of `src`
        `exclusionFilter` - a filter that matches files or folders that should _not_ be copied; null indicates that all files and folders should be copied
      Returns:
        the number of files (not directories) that were copied
      Throws:
        `IllegalArgumentException` - if the `src` or `dest` references are null
        `IOException`

    - #### convertFileToURL

          public static URL convertFileToURL(String filePath)
                                      throws MalformedURLException

      Utility to convert `File` to `URL`.
      Parameters:
        `filePath` - the path of the file
      Returns:
        the `URL` representation of the file.
      Throws:
        `MalformedURLException`
        `IllegalArgumentException` - if the file path is null, empty or blank

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.