org.jagatoo.util.io
Class FileUtils

java.lang.Object
  extended by org.jagatoo.util.io.FileUtils

public class FileUtils
extends java.lang.Object

Utility methods for files.

Author:
Marvin Froehlich (aka Qudus)

Method Summary
static void copyFile(java.io.File source, java.io.File dest)
          Copies one file to another one.
static void deleteFolderRecursively(java.io.File path)
          Deletes directory at path recursively.
static void deleteFolderRecursively(java.io.File path, boolean includeSelf)
          Deletes directory at path recursively.
static void deleteFolderRecursively(java.lang.String path)
          Deletes directory at path recursively.
static void deleteFolderRecursively(java.lang.String path, boolean includeSelf)
          Deletes directory at path recursively.
static java.io.File getCanonicalFile(java.io.File file)
           
static java.io.File getCanonicalFile(java.lang.String filename)
          Returns the canonical representation of the given file using File.getCanonicalFile().
static byte[] getFileAsByteArray(java.io.File file)
          Reads text-file file and returns contents as one big byte-array.
static java.lang.String getFileAsString(java.io.File file)
          Reads text-file file and returns contents as one big string.
static java.lang.String getFileAsString(java.io.File file, java.nio.charset.Charset charset)
           
static java.lang.String getFileAsString(java.io.File file, java.lang.String charset_name)
           
static void writeStringToFile(java.lang.CharSequence contents, java.io.File file)
          writes string contents to file file
static void writeStringToFile(java.lang.CharSequence contents, java.lang.String filename)
          writes string contents to file file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyFile

public static void copyFile(java.io.File source,
                            java.io.File dest)
                     throws java.io.IOException
Copies one file to another one.

Parameters:
source -
dest -
Throws:
java.io.IOException

deleteFolderRecursively

public static void deleteFolderRecursively(java.io.File path,
                                           boolean includeSelf)
                                    throws java.io.IOException
Deletes directory at path recursively.

Parameters:
path -
includeSelf - also delete the passed directory itself?
Throws:
java.io.IOException

deleteFolderRecursively

public static void deleteFolderRecursively(java.lang.String path,
                                           boolean includeSelf)
                                    throws java.io.IOException
Deletes directory at path recursively.

Parameters:
path -
includeSelf - also delete the passed directory itself?
Throws:
java.io.IOException

deleteFolderRecursively

public static void deleteFolderRecursively(java.io.File path)
                                    throws java.io.IOException
Deletes directory at path recursively.

Parameters:
path -
Throws:
java.io.IOException

deleteFolderRecursively

public static void deleteFolderRecursively(java.lang.String path)
                                    throws java.io.IOException
Deletes directory at path recursively.

Parameters:
path -
Throws:
java.io.IOException

writeStringToFile

public static void writeStringToFile(java.lang.CharSequence contents,
                                     java.io.File file)
                              throws java.io.IOException
writes string contents to file file

Parameters:
contents -
file -
Throws:
java.io.IOException

writeStringToFile

public static void writeStringToFile(java.lang.CharSequence contents,
                                     java.lang.String filename)
                              throws java.io.IOException
writes string contents to file file

Parameters:
contents -
filename -
Throws:
java.io.IOException

getFileAsByteArray

public static byte[] getFileAsByteArray(java.io.File file)
                                 throws java.io.IOException
Reads text-file file and returns contents as one big byte-array.

Parameters:
file -
Returns:
a byte-array
Throws:
java.io.IOException

getFileAsString

public static java.lang.String getFileAsString(java.io.File file)
                                        throws java.io.IOException
Reads text-file file and returns contents as one big string.

Parameters:
file -
Returns:
string
Throws:
java.io.IOException

getFileAsString

public static java.lang.String getFileAsString(java.io.File file,
                                               java.lang.String charset_name)
                                        throws java.io.IOException,
                                               java.io.UnsupportedEncodingException
Parameters:
file -
charset_name -
Returns:
Throws:
java.io.IOException
java.io.UnsupportedEncodingException

getFileAsString

public static java.lang.String getFileAsString(java.io.File file,
                                               java.nio.charset.Charset charset)
                                        throws java.io.IOException
Parameters:
file -
charset -
Returns:
Throws:
java.io.IOException

getCanonicalFile

public static final java.io.File getCanonicalFile(java.io.File file)

getCanonicalFile

public static final java.io.File getCanonicalFile(java.lang.String filename)
Returns the canonical representation of the given file using File.getCanonicalFile(). If this fails, the result of File.getAbsoluteFile() is returned.

Parameters:
filename -
Returns:
the canonical representation of the given file.