laser.util
Class FileUtils

java.lang.Object
  extended by laser.util.FileUtils

public class FileUtils
extends java.lang.Object

The FileUtils class provides several File related helper methods.

Author:
Heather M. Conboy (laser-software@cs.umass.edu)

Constructor Summary
FileUtils()
           
 
Method Summary
static void copy(java.io.File file1, java.io.File file2)
          Copies the first file to the second file.
static void copy(java.io.File sourceDir, java.io.File destDir, java.lang.String fileName)
          Copies the file from the source to the destination directory.
static void copy(java.lang.String fileName1, java.lang.String fileName2)
          Copies the first file to the second file.
static void copy(java.lang.String sourceDirName, java.lang.String destDirName, java.lang.String fileName)
          Copies the file from the source to the destination directory.
static java.lang.String getBaseName(java.lang.String fileName)
          Returns the base name of the given file name.
static java.lang.String getBaseName(java.lang.String fileName, java.lang.String fileExtension)
          Returns the base name of the given file name.
static java.lang.String getDirName(java.lang.String fileName)
          Returns the directory name of the given file name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

getBaseName

public static java.lang.String getBaseName(java.lang.String fileName)
Returns the base name of the given file name. This strips off the directory name if it existed as part of the file name.

NOTE: The file name must be non-null.

Parameters:
fileName - The name of the file of interest
Returns:
The base name

getBaseName

public static java.lang.String getBaseName(java.lang.String fileName,
                                           java.lang.String fileExtension)
Returns the base name of the given file name. This strips off the directory name and the given file extension if they existed as part of the file name.

NOTE: The file name and file extension must be non-null.

Parameters:
fileName - The name of the file of interest
fileExtension - The file extension to be removed if it exists as part of the file name
Returns:
The base name

getDirName

public static java.lang.String getDirName(java.lang.String fileName)
Returns the directory name of the given file name.

NOTE: The file name must be non-null.

Parameters:
fileName - The name of the file of interest
Returns:
The directory name

copy

public static void copy(java.io.File file1,
                        java.io.File file2)
                 throws java.io.IOException
Copies the first file to the second file.

PRECONDITIONS: It requires that file1 exists, is a file, and is readable and that file2 either doesn't exist or does exist, is a file, and is writable.

NOTES: This only works correctly for textual files. If file2 exists already and is writable, it will be overwritten.

Parameters:
file1 - The first file
file2 - The second file
Throws:
java.io.IOException - if an I/O error occurs

copy

public static void copy(java.lang.String fileName1,
                        java.lang.String fileName2)
                 throws java.io.IOException
Copies the first file to the second file.

PRECONDITIONS: It requires that fileName1 exists, is a file, and is readable and that fileName2 either doesn't exist or does exist, is a file, and is writable.

NOTES: This only works correctly for textual files. If file2 exists already and is writable, it will be overwritten.

Parameters:
fileName1 - The name of the first file
fileName2 - The name of the second file
Throws:
java.io.IOException - if an I/O error occurs

copy

public static void copy(java.io.File sourceDir,
                        java.io.File destDir,
                        java.lang.String fileName)
                 throws java.io.IOException
Copies the file from the source to the destination directory.

PRECONDITIONS: It requires that the source and destination directories exist and are directories. It also requires that sourceDir/fileName exists, is a file, and its readable and that destDir/fileName either doesn't exist or does exist, is a file, and is writable.

NOTES: This only works correctly for textual files. If the file exists already in the destination directory and is writable, it will be overwritten.

Parameters:
sourceDir - The source directory
destDir - The destination directory
fileName - The name of the file to copy
Throws:
java.io.IOException - if an I/O error occurs

copy

public static void copy(java.lang.String sourceDirName,
                        java.lang.String destDirName,
                        java.lang.String fileName)
                 throws java.io.IOException
Copies the file from the source to the destination directory.

PRECONDITIONS: It requires that the source and destination directories exist and are directories. It also requires that sourceDir/fileName exists, is a file, and its readable and that destDir/fileName either doesn't exist or does exist, is a file, and is writable.

NOTES: This only works correctly for textual files. If the file exists already in the destination directory and is writable, it will be overwritten.

Parameters:
sourceDirName - The name of the source directory
destDirName - The name of the destination directory
fileName - The name of the file to copy
Throws:
java.io.IOException - if an I/O error occurs