info.jonclark.util
Class FileUtils

java.lang.Object
  extended by info.jonclark.util.FileUtils

public class FileUtils
extends Object

Convenience methods for deailing with files


Constructor Summary
FileUtils()
           
 
Method Summary
 void copyFile(File in, File out)
          Copies a file using NIO
static File createFileWithPath(String path)
          Returns a file with the given path, which is guaranteed to exist on return
static String forceLeadingDotSlash(String str)
          Adds a leading ./ to a file path string if and only if the path string is not an absolute path.
static String forceTrailingSlash(String str)
          Adds a trailing slash to a directory path string if and only if the path string does not already end with a trailing slash.
static PrintStream getFileForWriting(File f)
           
static File[] getFilesWithExt(File root, String ext)
          Get files having extention
static boolean isAbsolutePath(String str)
          Determines whether a path string is a relative or absolute path.
static BufferedReader openTextFile(File f)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

copyFile

public void copyFile(File in,
                     File out)
              throws IOException
Copies a file using NIO

Parameters:
in - The source file
out - The destination file
Throws:
IOException

createFileWithPath

public static File createFileWithPath(String path)
                               throws IOException
Returns a file with the given path, which is guaranteed to exist on return

Parameters:
path -
Returns:
Throws:
IOException

openTextFile

public static BufferedReader openTextFile(File f)
                                   throws FileNotFoundException
Throws:
FileNotFoundException

getFileForWriting

public static PrintStream getFileForWriting(File f)
                                     throws FileNotFoundException
Throws:
FileNotFoundException

forceTrailingSlash

public static String forceTrailingSlash(String str)
Adds a trailing slash to a directory path string if and only if the path string does not already end with a trailing slash. This ensures that a filename appended to the end of the string will function as a filename and not an invalid directory name.

Parameters:
str - The path string
Returns:
The path string guaranteed to end with a slash

forceLeadingDotSlash

public static String forceLeadingDotSlash(String str)
Adds a leading ./ to a file path string if and only if the path string is not an absolute path. This is necessary for relative paths that contain only one file if the getParentFile() method of File class is to work properly.

Parameters:
str -
Returns:

isAbsolutePath

public static boolean isAbsolutePath(String str)
Determines whether a path string is a relative or absolute path.

Parameters:
str - The path string to be analyzed
Returns:
True iff the file is a UNIX, DOS, or Windows absolute path

getFilesWithExt

public static File[] getFilesWithExt(File root,
                                     String ext)
Get files having extention

Parameters:
ext - e.g. ".txt"
Returns: