gov.sandia.cognition.io
Class FileUtil

java.lang.Object
  extended by gov.sandia.cognition.io.FileUtil

@CodeReview(reviewer="Jonathan McClain",
            date="2006-05-11",
            changesNeeded=false,
            comments="No changes necessary.")
public final class FileUtil
extends Object

The FileUtil class defines some useful utilities for dealing with files.

Since:
1.0
Author:
Justin Basilico

Constructor Summary
FileUtil()
           
 
Method Summary
static boolean couldWrite(File file)
          Attempts to determine if the application might be able to write to the given file, which may or may not already exists.
static String getExtension(File file)
          Returns the extension of the given file, which is the part of the name after the last '.'.
static String getExtension(String fileName)
          Returns the extension of the given filename , which is the part of the name after the last '.'.
static String removeExtension(String fileName)
          Takes a file name and returns the name of the file without the extension on it.
 
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

getExtension

public static String getExtension(File file)
Returns the extension of the given file, which is the part of the name after the last '.'.

Parameters:
file - The File to get the extension from.
Returns:
The extension part of the given File.
Since:
1.0

getExtension

public static String getExtension(String fileName)
Returns the extension of the given filename , which is the part of the name after the last '.'.

Parameters:
fileName - The file name to get the extension from.
Returns:
The extension part of the given file name.
Since:
1.0

removeExtension

public static String removeExtension(String fileName)
Takes a file name and returns the name of the file without the extension on it. The extension is determined by finding the last '.' that appears in the name. If the last '.' is the first character or there is no '.' then the full file name is returned.

Parameters:
fileName - A file name.
Returns:
The portion of the name before the extension
Since:
2.0

couldWrite

public static boolean couldWrite(File file)
Attempts to determine if the application might be able to write to the given file, which may or may not already exists. If the file exists, it just calls the canWrite() method on it. Otherwise, it looks at its parent directory to see if that exists and checks to see if that directory can be written to.

Parameters:
file - The file (which may or may not already exist) to see if it can be written to.
Returns:
True if it should be possible to write to the given file.