com.oktiva.util
Class FileUtil

java.lang.Object
  extended bycom.oktiva.util.FileUtil

public final class FileUtil
extends java.lang.Object

File utility class.

Original code from http://forum.java.sun.com

Version:
$Id: FileUtil.java,v 1.1 2005/01/17 20:11:19 itamarc Exp $

Field Summary
static java.lang.String lineFeed
          Allows cross-platform compatibility.
 
Method Summary
static void copy(java.io.File src, java.io.File dest)
          Copy files and/or directories.
static void deleteFile(java.io.File file)
          Deletes a file or a directory along with all files and directories it contains.
static java.lang.String readFile(java.io.File file)
          Returns a string containing the contents of a file.
static java.lang.String readFile(java.io.FileReader fileReader)
          Returns a string containing the contents of a file.
static java.lang.String readFile(java.lang.String filename)
          Returns a string containing the contents of a file.
static java.lang.String[] readFileAsArray(java.io.File file)
          Returns a string array containing the contents of a file (one line en each array item).
static java.lang.String[] readFileAsArray(java.io.FileReader fileReader)
          Returns a string array containing the contents of a file (one line en each array item).
static java.lang.String[] readFileAsArray(java.lang.String filename)
          Returns a string array containing the contents of a file (one line en each array item).
static void writeFile(java.lang.String text, java.io.File file)
          Write a string to a file.
static void writeFile(java.lang.String text, java.io.FileWriter fileWriter)
          Write a string to a file.
static void writeFile(java.lang.String text, java.lang.String filename)
          Write a string to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineFeed

public static final java.lang.String lineFeed
Allows cross-platform compatibility.

Method Detail

copy

public static final void copy(java.io.File src,
                              java.io.File dest)
                       throws java.io.IOException
Copy files and/or directories.

Parameters:
src - source file or directory
dest - destination file or directory
Throws:
java.io.IOException - if operation fails

deleteFile

public static final void deleteFile(java.io.File file)
                             throws java.io.IOException
Deletes a file or a directory along with all files and directories it contains.

Parameters:
file - the file or directory to delete
Throws:
java.io.IOException - if operation fails

readFile

public static final java.lang.String readFile(java.io.File file)
                                       throws java.io.IOException
Returns a string containing the contents of a file.

Parameters:
file - the file to read
Returns:
the contents of the file
Throws:
java.io.IOException

readFile

public static final java.lang.String readFile(java.lang.String filename)
                                       throws java.io.IOException
Returns a string containing the contents of a file.

Parameters:
filename - the name of the file
Returns:
the contents of the file
Throws:
java.io.IOException

readFile

public static final java.lang.String readFile(java.io.FileReader fileReader)
                                       throws java.io.IOException
Returns a string containing the contents of a file.

Parameters:
fileReader - the FileReader to use
Returns:
the contents of the file
Throws:
java.io.IOException

readFileAsArray

public static final java.lang.String[] readFileAsArray(java.io.File file)
                                                throws java.io.IOException
Returns a string array containing the contents of a file (one line en each array item).

Parameters:
file - the file to read
Returns:
the contents of the file split in an array
Throws:
java.io.IOException

readFileAsArray

public static final java.lang.String[] readFileAsArray(java.lang.String filename)
                                                throws java.io.IOException
Returns a string array containing the contents of a file (one line en each array item).

Parameters:
filename - the name of the file
Returns:
the contents of the file split in an array
Throws:
java.io.IOException

readFileAsArray

public static final java.lang.String[] readFileAsArray(java.io.FileReader fileReader)
                                                throws java.io.IOException
Returns a string array containing the contents of a file (one line en each array item).

Parameters:
fileReader - the FileReader to use
Returns:
the contents of the file split in an array
Throws:
java.io.IOException

writeFile

public static final void writeFile(java.lang.String text,
                                   java.io.File file)
                            throws java.io.IOException
Write a string to a file.

Parameters:
text - The string to write to the file.
file - The file to write.
Throws:
java.io.IOException - If the write operation fails.

writeFile

public static final void writeFile(java.lang.String text,
                                   java.lang.String filename)
                            throws java.io.IOException
Write a string to a file.

Parameters:
text - The string to write to the file.
filename - The name of the file to write.
Throws:
java.io.IOException - If the write operation fails.

writeFile

public static final void writeFile(java.lang.String text,
                                   java.io.FileWriter fileWriter)
                            throws java.io.IOException
Write a string to a file.

Parameters:
text - The string to write to the file.
fileWriter - The FileWriter to use
Throws:
java.io.IOException - If the write operation fails.