edu.northwestern.at.utils

## Class FileUtils

- java.lang.Object
- - edu.northwestern.at.utils.FileUtils

-     public class FileUtils
      extends java.lang.Object

  File utilities.

  This static class provides various utility methods for manipulating files.

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `FileUtils()` Don't allow instantiation but do allow overrides.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `chdir(java.lang.String directory)` Change the current directory.
    `static boolean` | `copyFile(java.lang.String srcFileName, java.lang.String destFileName)` Copy a file.
    `static boolean` | `createPath(java.io.File directory)` Create intermediate directories for a directory path.
    `static boolean` | `createPathForFile(java.lang.String fileName)` Create directory for specified file name.
    `static boolean` | `deleteFile(java.lang.String fileName)` Delete named file.
    `static java.lang.String` | `getCurrentDirectory()` Get the current directory.
    `static java.lang.String` | `readTextFile(java.io.File file)` Read text file to a string.
    `static java.lang.String` | `readTextFile(java.io.File file, java.lang.String encoding)` Read text file to a string.
    `static java.lang.String` | `readTextFile(java.io.Reader reader)` Read text file to a string.
    `static java.lang.String` | `readTextFile(java.lang.String fileName)` Read text file to a string.
    `static java.lang.String` | `readTextFile(java.lang.String fileName, java.lang.String encoding)` Read text file to a string.
    `static void` | `writeTextFile(java.io.File file, boolean append, java.util.List contents, java.lang.String encoding)` Write text file from a list of strings.
    `static void` | `writeTextFile(java.io.File file, boolean append, java.lang.String contents)` Write text file from a string.
    `static void` | `writeTextFile(java.io.File file, boolean append, java.lang.String[] contents, java.lang.String encoding)` Write text file from an array of strings.
    `static void` | `writeTextFile(java.io.File file, boolean append, java.lang.String contents, java.lang.String encoding)` Write text file from a string.
    `static void` | `writeTextFile(java.lang.String fileName, boolean append, java.lang.String contents)` Write text file from a string.
    `static void` | `writeTextFile(java.lang.String fileName, boolean append, java.lang.String contents, java.lang.String encoding)` Write text file from a string.

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

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

- - ### Constructor Detail

    - #### FileUtils

          protected FileUtils()

      Don't allow instantiation but do allow overrides.

  - ### Method Detail

    - #### readTextFile

          public static java.lang.String readTextFile(java.io.File file,
                                      java.lang.String encoding)
                                               throws java.io.IOException

      Read text file to a string.
      Parameters:
        `file` - Text file to read from.
        `encoding` - Text file encoding, e.g., "utf-8".
      Returns:
        Contents of file as a string.
      Throws:
        `java.io.IOException` - if file cannot be read.

    - #### readTextFile

          public static java.lang.String readTextFile(java.io.Reader reader)
                                               throws java.io.IOException

      Read text file to a string.
      Parameters:
        `reader` - Reader to read from.
      Returns:
        Contents of file as a string.
      Throws:
        `java.io.IOException` - if file cannot be read.

    - #### readTextFile

          public static java.lang.String readTextFile(java.io.File file)
                                               throws java.io.IOException

      Read text file to a string.
      Parameters:
        `file` - Text file to read from. Assumed to be utf-8 encoded.
      Returns:
        Contents of file as a string.
      Throws:
        `java.io.IOException` - if file cannot be read.

    - #### readTextFile

          public static java.lang.String readTextFile(java.lang.String fileName,
                                      java.lang.String encoding)
                                               throws java.io.IOException

      Read text file to a string.
      Parameters:
        `fileName` - Text file name to read from.
        `encoding` - Text file encoding, e.g., "utf-8".
      Returns:
        Contents of file as a string.
      Throws:
        `java.io.IOException` - if file cannot be read.

    - #### readTextFile

          public static java.lang.String readTextFile(java.lang.String fileName)
                                               throws java.io.IOException

      Read text file to a string.
      Parameters:
        `fileName` - Text file name to read from. Assumed to be utf-8 encoded.
      Returns:
        Contents of file as a string.
      Throws:
        `java.io.IOException` - if file cannot be read.

    - #### writeTextFile

          public static void writeTextFile(java.io.File file,
                           boolean append,
                           java.lang.String contents,
                           java.lang.String encoding)
                                    throws java.io.IOException

      Write text file from a string.
      Parameters:
        `file` - Text file to write to.
        `contents` - String to write to file.
        `append` - True to append contents to existing file.
        `encoding` - Text file encoding, e.g., "utf-8".
      Throws:
        `java.io.IOException` - in case of I/O exception.

    - #### writeTextFile

          public static void writeTextFile(java.io.File file,
                           boolean append,
                           java.lang.String[] contents,
                           java.lang.String encoding)
                                    throws java.io.IOException

      Write text file from an array of strings.
      Parameters:
        `file` - Text file to write to.
        `contents` - Strings to write to file.
        `append` - True to append contents to existing file.
        `encoding` - Text file encoding, e.g., "utf-8".
      Throws:
        `java.io.IOException` - in case of I/O exception.

    - #### writeTextFile

          public static void writeTextFile(java.io.File file,
                           boolean append,
                           java.util.List contents,
                           java.lang.String encoding)
                                    throws java.io.IOException

      Write text file from a list of strings.
      Parameters:
        `file` - Text file to write to.
        `contents` - List of strings to write to file.
        `append` - True to append contents to existing file.
        `encoding` - Text file encoding, e.g., "utf-8".
      Throws:
        `java.io.IOException` - in case of I/O exception.

    - #### writeTextFile

          public static void writeTextFile(java.io.File file,
                           boolean append,
                           java.lang.String contents)
                                    throws java.io.IOException

      Write text file from a string.
      Parameters:
        `file` - Text file to write to.
        `contents` - String to write to file.
        `append` - True to append contents to existing file.
      Throws:
        `java.io.IOException` - in case of I/O exception.

        File is written in utf-8 encoding.

    - #### writeTextFile

          public static void writeTextFile(java.lang.String fileName,
                           boolean append,
                           java.lang.String contents,
                           java.lang.String encoding)
                                    throws java.io.IOException

      Write text file from a string.
      Parameters:
        `fileName` - Text file name to write to.
        `contents` - String to write to file.
        `append` - True to append contents to existing file.
      Throws:
        `java.io.IOException` - in case of I/O exception.

    - #### writeTextFile

          public static void writeTextFile(java.lang.String fileName,
                           boolean append,
                           java.lang.String contents)
                                    throws java.io.IOException

      Write text file from a string.
      Parameters:
        `fileName` - Text file name to write to.
        `contents` - String to write to file.
        `append` - True to append contents to existing file.
      Throws:
        `java.io.IOException` - in case of I/O exception.

        File is written in utf-8 encoding.

    - #### copyFile

          public static boolean copyFile(java.lang.String srcFileName,
                         java.lang.String destFileName)

      Copy a file.
      Parameters:
        `srcFileName` - Name of source file to copy.
        `destFileName` - Name of destination file to which to copy.
      Returns:
        true if copy successful.

    - #### createPath

          public static boolean createPath(java.io.File directory)

      Create intermediate directories for a directory path.
      Parameters:
        `directory` - The subdirectory for which to create any missing intermediate directories.
      Returns:
        true if all the intermediate directories were created successfully, or the directory already exists.

    - #### createPathForFile

          public static boolean createPathForFile(java.lang.String fileName)

      Create directory for specified file name.
      Parameters:
        `fileName` - File name for which to create parent directory, if necessary.
      Returns:
        True if directory created successfully.

    - #### getCurrentDirectory

          public static java.lang.String getCurrentDirectory()

      Get the current directory.
      Returns:
        The current directory from the "user.dir" system property.

    - #### chdir

          public static java.lang.String chdir(java.lang.String directory)

      Change the current directory.
      Parameters:
        `directory` - New directory to which to move. Ignored if null.
      Returns:
        Previous directory.

    - #### deleteFile

          public static boolean deleteFile(java.lang.String fileName)

      Delete named file.
      Parameters:
        `fileName` - Name of file to delete.
      Returns:
        True if file deleted, or file did not exist and so did not need to be deleted.