org.eclipse.rdf4j.common.io

## Class FileUtil

- java.lang.Object
- - org.eclipse.rdf4j.common.io.FileUtil

-     public class FileUtil
      extends Object

  Utility methods for operations on Files.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FileUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `copyFile(File source, File destination)` Copies the contents of file `source` to file `destination`.
    `static void` | `createDirIfNotExists(File dir)` Creates a directory if it doesn't exist yet.
    `static File` | `createTempDir(String prefix)` Deprecated. use `Files.createTempDirectory(String, java.nio.file.attribute.FileAttribute...)` instead
    `static boolean` | `deleteChildren(File directory)` Deletes all files and subdirectories in the specified directory.
    `static void` | `deleteDir(File dir)` Deletes the specified directory and any files and directories in it recursively.
    `static boolean` | `deleteFiles(File directory)` Deletes all files in the specified directory.
    `static boolean` | `deltree(File directory)` Deletes a directory, recursively deleting all the files and subdirectories in it, or just a file.
    `static String` | `getFileExtension(String fileName)` Gets the extension of the specified file name.
    `static File` | `getRelativeFile(File subj, File relativeTo)` Gets the relative representations of a file compared to another.
    `static String` | `getRelativePath(File subj, File relativeTo)` Gets the relative representations of a file compared to another.
    `static boolean` | `isLegalFileName(String fileName)` Checks whether the specified file name is a legal (DOS/Windows-) file name.
    `static boolean` | `isLegalFileNameChar(char c)` Checks whether the specified character is a legal (DOS/Windows-) file name character.
    `static boolean` | `moveRecursive(File from, File to, Collection<File> excludes)` Moves the given file and all files under it (if it's a directory) to the given location, excluding the given collection of File objects!

    - ### 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

    - #### getRelativePath

          public static String getRelativePath(File subj,
                                               File relativeTo)

      Gets the relative representations of a file compared to another.
      Parameters:
        `subj` - The File to find the relative form for.
        `relativeTo` - The File 'subj' should be made relative to.
      Returns:
        The relative representation of subj.

    - #### getRelativeFile

          public static File getRelativeFile(File subj,
                                             File relativeTo)

      Gets the relative representations of a file compared to another.
      Parameters:
        `subj` - The File to find the relative form for.
        `relativeTo` - The File 'subj' should be made relative to.
      Returns:
        The relative representation of subj.

    - #### getFileExtension

          public static String getFileExtension(String fileName)

      Gets the extension of the specified file name.
      Parameters:
        `fileName` - A file name.
      Returns:
        The file name extension (e.g. "exe" or "txt"), or `null` if the file name does not have a (valid) extension.

    - #### isLegalFileName

          public static boolean isLegalFileName(String fileName)

      Checks whether the specified file name is a legal (DOS/Windows-) file name.
      Parameters:
        `fileName` - name of the file
      Returns:
        true if all characters of the name are legal to use

    - #### isLegalFileNameChar

          public static boolean isLegalFileNameChar(char c)

      Checks whether the specified character is a legal (DOS/Windows-) file name character.
      Parameters:
        `c` - character to check
      Returns:
        true if character is legal to use

    - #### copyFile

          public static void copyFile(File source,
                                      File destination)
                               throws IOException

      Copies the contents of file `source` to file `destination`.
      Parameters:
        `source` - source file
        `destination` - destination file
      Throws:
        `IOException`

    - #### createDirIfNotExists

          public static void createDirIfNotExists(File dir)
                                           throws IOException

      Creates a directory if it doesn't exist yet.
      Parameters:
        `dir` - The directory to create.
      Throws:
        `IOException` - If the creation of the directory failed.

    - #### deltree

          public static boolean deltree(File directory)

      Deletes a directory, recursively deleting all the files and subdirectories in it, or just a file.
      Parameters:
        `directory` - file or directory to delete
      Returns:
        true if all files were deleted successfully.

    - #### deleteFiles

          public static boolean deleteFiles(File directory)

      Deletes all files in the specified directory. Nothing happens when the specified File is not a directory.
      Parameters:
        `directory` -
      Returns:
        true when all files in the specified directory were successfully deleted, when there where no files or when the specified file was not a directory.

    - #### deleteChildren

          public static boolean deleteChildren(File directory)

      Deletes all files and subdirectories in the specified directory. Nothing happens when the specified File is not a directory.
      Parameters:
        `directory` -
      Returns:
        true when all children were successfully deleted, when there were no children or when the file was not a directory.

    - #### moveRecursive

          public static boolean moveRecursive(File from,
                                              File to,
                                              Collection<File> excludes)

      Moves the given file and all files under it (if it's a directory) to the given location, excluding the given collection of File objects!
      Parameters:
        `from` - File or directory to be moved
        `to` - The file or directory to rename to
        `excludes` - The File objects to be excluded; if a directory is excluded, all files under it are excluded as well!
      Returns:
        Whether moving was successful

    - #### createTempDir

          @Deprecated
          public static File createTempDir(String prefix)
                                                throws IOException

      Deprecated. use `Files.createTempDirectory(String, java.nio.file.attribute.FileAttribute...)` instead
      Creates a new and empty directory in the default temp directory using the given prefix.
      Parameters:
        `prefix` - The prefix string to be used in generating the directory's name; must be at least three characters long.
      Returns:
        A newly-created empty directory.
      Throws:
        `IOException` - If no directory could be created.

    - #### deleteDir

          public static void deleteDir(File dir)
                                throws IOException

      Deletes the specified directory and any files and directories in it recursively.
      Parameters:
        `dir` - The directory to remove.
      Throws:
        `IOException` - If the directory could not be removed.

Copyright © 2015-2021 Eclipse Foundation. All Rights Reserved.