de.jstacs.io
Class FileManager

java.lang.Object
  extended by de.jstacs.io.FileManager

public class FileManager
extends Object

This class is for handling files. The most important methods of this class are for writing a StringBuffer to or reading it from a file. This is useful for all object that implement Storable and should be saved in or loaded from a file.

Author:
Jens Keilwagen
See Also:
Storable

Method Summary
static void copy(String from, String to)
          This method copies a file in a faster manner.
static void copy(String from, String to, byte[] buffer)
          This method copies a file in a faster manner using a specified buffer.
static int copyDiff(File source, File target, Date date, boolean recursive, FileFilter filter)
          This method copies all files and directories, if selected, from a source to a target that have been modified after a predefined date
static StringBuffer readFile(File file)
          This method reads a StringBuffer from a given file.
static void writeFile(File outputFile, StringBuffer buffer)
          This method saves a StringBuffer to a given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyDiff

public static int copyDiff(File source,
                           File target,
                           Date date,
                           boolean recursive,
                           FileFilter filter)
                    throws IllegalArgumentException,
                           IOException
This method copies all files and directories, if selected, from a source to a target that have been modified after a predefined date

Parameters:
source - the source directory
target - the target directory
date - the date
recursive - a switch if this method should be used recursively in the subdirectories
filter - a filter for the files, taht enables the user to copy only specific files
Returns:
the number of copied files.
Throws:
IllegalArgumentException
IOException

copy

public static void copy(String from,
                        String to)
                 throws IOException
This method copies a file in a faster manner.

Parameters:
from - the file name of the original file
to - the file name of the copied file
Throws:
IOException - if something went wrong

copy

public static void copy(String from,
                        String to,
                        byte[] buffer)
                 throws IOException
This method copies a file in a faster manner using a specified buffer.

Parameters:
from - the file name of the original file
to - the file name of the copied file
buffer - an array for reading the content of the original file, the size of the array determines how many byte are read at ones.
Throws:
IOException - if something went wrong

readFile

public static StringBuffer readFile(File file)
                             throws IOException
This method reads a StringBuffer from a given file.

Parameters:
file - the file to be read
Returns:
a Stringbuffer with the content of the file
Throws:
IOException - if something went wrong with the file

writeFile

public static void writeFile(File outputFile,
                             StringBuffer buffer)
                      throws IOException
This method saves a StringBuffer to a given file.

Parameters:
outputFile - the file into which the output should be written
buffer - the buffer to be written in a file
Throws:
IOException - if something went wrong with the file