dsto.dfc.util
Class Files

java.lang.Object
  extended by dsto.dfc.util.Files

public final class Files
extends Object

General file utilities

Version:
$Revision$
Author:
Matthew

Method Summary
static File addDefaultExtension(File file, String extension)
          Add a default extension to a file if it does not already have one.
static String addDefaultExtension(String file, String extension)
           
static void copyFile(File srcFile, File trgFile)
          Copy one file to another.
static void copyFile(String srcFile, String trgFile)
          Copy one file to another.
static String getExtension(File file)
          Get the extension from a file's name.
static String getExtension(String name)
           
static String readScriptLine(Reader input)
          Read the next line from a "script-like stream", where script-like streams are line-oriented text streams with "#" comments and \ as a line-continuation operator, similar to Bourne shell scripts and Java .property files.
static String readString(Reader reader)
          Read all of the content supplied by a Reader into a String.
static StringBuilder readStringBuilder(Reader reader)
          Read all of the content supplied by a Reader into a StringBuilder.
static String removeExtension(File file)
           
static String removeExtension(String fileName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getExtension

public static String getExtension(File file)
Get the extension from a file's name.

Parameters:
file - The file to examine.
Returns:
The extension, or "" if none.

getExtension

public static String getExtension(String name)

removeExtension

public static String removeExtension(File file)

removeExtension

public static String removeExtension(String fileName)

addDefaultExtension

public static File addDefaultExtension(File file,
                                       String extension)
Add a default extension to a file if it does not already have one.

Parameters:
file - The file to examine.
extension - The extension to add.
Returns:
The modified file.

addDefaultExtension

public static String addDefaultExtension(String file,
                                         String extension)

copyFile

public static void copyFile(File srcFile,
                            File trgFile)
                     throws IOException
Copy one file to another.

Throws:
IOException
See Also:
copyFile(String, String)

copyFile

public static void copyFile(String srcFile,
                            String trgFile)
                     throws IOException
Copy one file to another.

Parameters:
srcFile - The source file.
trgFile - The target file.
Throws:
IOException - if an error occurs.

readString

public static String readString(Reader reader)
                         throws IOException
Read all of the content supplied by a Reader into a String.

Parameters:
reader - The reader.
Returns:
The entire contents of reader as a String.
Throws:
IOException - if an error occurs while reading.
See Also:
readStringBuilder(Reader)

readStringBuilder

public static StringBuilder readStringBuilder(Reader reader)
                                       throws IOException
Read all of the content supplied by a Reader into a StringBuilder.

Parameters:
reader - The reader.
Returns:
The entire contents of reader as a StringBuilder.
Throws:
IOException - if an error occurs while reading.

readScriptLine

public static String readScriptLine(Reader input)
                             throws IOException
Read the next line from a "script-like stream", where script-like streams are line-oriented text streams with "#" comments and \ as a line-continuation operator, similar to Bourne shell scripts and Java .property files. White space at the start and end of the line is ignored, as are lines starting with "#".

Parameters:
input - The input stream.
Returns:
The next line read (will never be "") or null if at end of stream.
Throws:
IOException - if an error occurs reading the stream.


Copyright © 2008 Commonwealth of Australia