ptolemy.copernicus.c
Class FileHandler

java.lang.Object
  extended by ptolemy.copernicus.c.FileHandler

public class FileHandler
extends java.lang.Object

A class that takes care of common File I/O functions.

Since:
Ptolemy II 2.0
Version:
$Id: FileHandler.java,v 1.31 2006/10/24 23:50:27 cxh Exp $
Author:
Ankush Varma
Accepted Rating:
Red (ankush)
Proposed Rating:
Red (ankush)

Constructor Summary
FileHandler()
           
 
Method Summary
static boolean exists(java.lang.String fileName)
          Tells whether a file or directory with a given name exists.
static java.lang.Object readObject(java.lang.String fileName)
          Reads an object from a specified file.
static java.lang.String readStringFromFile(java.lang.String fileName)
          Reads the contents of a text file and returns them as a String.
static void write(java.lang.String fileName, java.lang.Object object)
          Write out the given Object to a file.
static void write(java.lang.String fileName, java.lang.String code)
          Write out the given string to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHandler

public FileHandler()
Method Detail

exists

public static boolean exists(java.lang.String fileName)
Tells whether a file or directory with a given name exists.

Parameters:
fileName - A fileName.
Returns:
True if a file or directory with that name exists.

readObject

public static java.lang.Object readObject(java.lang.String fileName)
Reads an object from a specified file.

Parameters:
fileName - The file to read.
Returns:
The object in this file.

readStringFromFile

public static java.lang.String readStringFromFile(java.lang.String fileName)
Reads the contents of a text file and returns them as a String. Prints an error statement and returns an empty string if an IO error occurs.

Parameters:
fileName - The file to read from.
Returns:
A String containing the entire contents of the file.

write

public static void write(java.lang.String fileName,
                         java.lang.String code)
Write out the given string to a file.

Parameters:
fileName - The file to write to.
code - The String to write.
Throws:
java.lang.RuntimeException - If it fails to write.

write

public static void write(java.lang.String fileName,
                         java.lang.Object object)
Write out the given Object to a file.

Parameters:
fileName - The file to write to.
object - The object to write.