edu.northwestern.at.utils
Class FileUtils

java.lang.Object
  extended by 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
protected FileUtils()
          Don't allow instantiation but do allow overrides.
 
Method Summary
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 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.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.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 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.File file)
                                     throws java.io.IOException
Read text file to a string.

Parameters:
file - Text file 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.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.
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)
                          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.

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.

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.

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.