net.charlesames.utility.io
Class FileMethods

java.lang.Object
  extended by net.charlesames.utility.io.FileMethods

public abstract class FileMethods
extends java.lang.Object

Miscellaneous methods concerned with files.

Author:
Charles Ames

Constructor Summary
FileMethods()
           
 
Method Summary
static boolean fileEquals(java.io.File file1, java.io.File file2)
           
static java.lang.String getFileExtension(java.io.File file)
          Get the portion of the file name following the last dot.
static java.lang.String getFileNameWithoutExtension(java.io.File file)
          Get the portion of the filename up to, but not including, the last dot.
static java.io.File getNewFile(javax.swing.JFrame frame, javax.swing.JFileChooser chooser, java.io.File suggestedFile)
           
static java.lang.String getRelativePath(java.io.File targetFile, java.io.File baseDirectory)
          Adapted from http://stackoverflow.com/questions/204784/how-to-construct-a-relative-path-in-java-from-two-absolute-paths-or-urls Get the path from a file relative to a base directory.
static java.lang.String readAll(java.io.File file)
          Reads character data from a file in a privileged context.
static void writeAll(java.io.File file, java.lang.String text)
          Writes character data to a file in a privileged context.
static void writeAll(java.io.File file, java.lang.String text, java.lang.String encoding)
          Writes character data to a file in a privileged context.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileMethods

public FileMethods()
Method Detail

getFileExtension

public static java.lang.String getFileExtension(java.io.File file)
Get the portion of the file name following the last dot.

Parameters:
file - The file.
Returns:
The portion of the file name following the last dot.

getFileNameWithoutExtension

public static java.lang.String getFileNameWithoutExtension(java.io.File file)
Get the portion of the filename up to, but not including, the last dot.

Parameters:
file - The file.
Returns:
The portion of the filename up to, but not including, the last dot.

readAll

public static java.lang.String readAll(java.io.File file)
Reads character data from a file in a privileged context.

Parameters:
file - The file which contains the text.
Returns:
The text content of the file.

writeAll

public static void writeAll(java.io.File file,
                            java.lang.String text)
Writes character data to a file in a privileged context.

Parameters:
file - The file which is to receive the text.
text - A long string which is to be written to the file.

writeAll

public static void writeAll(java.io.File file,
                            java.lang.String text,
                            java.lang.String encoding)
Writes character data to a file in a privileged context.

Parameters:
file - The file which is to receive the text.
text - Text data which is to be written to the file.
encoding - A long string which is to be written to the file.

getNewFile

public static java.io.File getNewFile(javax.swing.JFrame frame,
                                      javax.swing.JFileChooser chooser,
                                      java.io.File suggestedFile)
Parameters:
frame - The highest-level GUI object (JFrame)
chooser -
suggestedFile - An absolute file path
Returns:
The selected file (null if cancelled).

getRelativePath

public static java.lang.String getRelativePath(java.io.File targetFile,
                                               java.io.File baseDirectory)
Adapted from http://stackoverflow.com/questions/204784/how-to-construct-a-relative-path-in-java-from-two-absolute-paths-or-urls Get the path from a file relative to a base directory.

Parameters:
targetFile - targetPath is calculated to this file
baseDirectory - basePath is calculated from this directory
Returns:
The relative path from the baseDirectory to the targetFile.

fileEquals

public static boolean fileEquals(java.io.File file1,
                                 java.io.File file2)
Parameters:
file1 -
file2 -
Returns:
True if file1 and file2 are both null or if file1 and file2 are the same; false otherwise.