type.lang
Class IO

java.lang.Object
  extended by type.lang.IO

public class IO
extends java.lang.Object

The IO class provides a collection of static services to facilitate I/O. All fields and methods in this class are static and, hence, you access them through the class itself (rather than through an instance).

The I/O services provide support for console I/O, formatting, object I/O, graphics, and I/O Capture. And although there seems to be a large number of methods, they are actually mere variations of only six:

The class provides, as well, two class variables that are pre-connected to Standard Input and Output. Using them, you can access the methods in UniReader and UniWriter to perform more general i/o. For example, they allow you to read multiple values per line from the user.


1. Formatting Services
These services return strings and consist of the repeat(int, char) method and a number of overloaded format methods. The format methods receive the value to be formatted (which can be of any type) and a format descriptor: a string that contains one or more of the following flags in any order and in any case:

The format methods are tolerant when parsing the format descriptor: If you specify a meaningless flag (e.g. S for string values) it will simply be ignored, and if you specify conflicting flags (e.g. both S and X), the extra flags are ignored according to the following precedence: Base (decimal, hex or binary) then notation (standard or scientific) then thousand-separator then zero-fill. Furthermore, if w is specified and the formatted string is longer than it, the specified width is ignored.

A RuntimeException will occur, however, if any other character is included in the descriptor.

Formatting Examples:

  format((byte) 13, "b") = "00001101"
  format((byte) 112, "x") = "70"
  format((int) 315, "x") = "0000013b"
  format((int) 315, "6z") = "000315"
  format((int) 1415675, "12,") = "   1,415,675"
  format((double) 17563737.347357, ",15.2") = "  17,563,737.35"
  format((double) 6785367322.763586, "10.2s") = "    6.79E9"

2. Input Services
These services allow your program to read data from Standard Input, which is typically connected to the keyboard.

There are several read methods that are all line oriented; i.e. they read an entire line from the user, and attempt to interpret it as representing a value of the method's return type. If the attempt is successful, the interpreted value is returned, otherwise, an exception is thrown.

Input Examples:


3. Output Services
These services allow you to display output on Standard Output, which is typically connected to the screen.

There is effectively only one: the print method but overloading, line separator option, and formatting, give rise to the many variations of this single method.

Output Examples:
Suppose we want to compute the square and the square root of the number 105 (we would normally read the number, and possibly the format descriptors, from the user but we seek a simple example that focuses on the services of this class:

 import type.lang.*;
 public class Out
 {  public static void main (String[] args)
    {  int num = 105;
       int square = num * num;
       double root = Math.sqrt(num);
       //----------------------------------Unformatted
       IO.print(square);
       IO.print(" ");
       IO.println(root);
       //----------------------------------Some formatting
       IO.print(square, "10");
       IO.println(root, "15.2");
       //----------------------------------More formatting
       IO.print(square, "10L");
       IO.println(root, ",15.4");
       //----------------------------------Scientific
       IO.print(square, ",10");
       IO.println(root, ",15.6s");
       //----------------------------------Hex
       IO.print(square, "x10");
       IO.println(root, "x20");
    }
 }
Here's the output:
 11025 10.246950765959598
      11025          10.25
 11025             10.2470
     11,025     1.024695E1
 0000000000002b11    40247e7054af0989
See formatting for details on the format descriptor.


4. Object I/O Services
The printObject method enables applications to achieve state persistance by storing all their (serializable) objects in a file prior to exiting. This enables re-instatiation of (non-static) state in a later session via the readObject method..

Object Storage Example:
Suppose we want to create a file "objDatabase" containing a particular Stock object so that we can later retrieve:

 import type.lang.*;
 public class WriteStock
 {  public static void main (String[] args)
    {  ...
     Stock stk = new Stock("ry");
     IO.printObject(stk, "objDatabase");
    }
 }
And to read this file:
 import type.lang.*;
 public class ReadStock
 {  public static void main (String[] args)
    {  Stock stk = (Stock) IO.readObject("objDatabase");
       ...
    }
 }


5. Graphics
You can use these services to obtain a reference to a panel on which you can draw graphics. The returned panel is a swing JPanel and can be drawn on using the Graphics2D context. See the UniPanel UniPanel class for a complete example. Note that two methods are provided:


6. I/O Capture
Given an app that reads input from standard input and generates output on standard output, this service allows us to write a test harness that passes input to it as a string and capture its output also as a string. See launch(java.lang.String, java.lang.String) for details.

Version:
3.0 (Summer 2000), 3.5 (Summer 2001), 4.0 (Summer 2002), , 4.5 (Summer 2003)
Author:
H. Roumani, roumani@cs.yorku.ca

Field Summary
static char fillChar
          This field specifies the character to use for padding.
static UniReader in
          This field is pre-connected to Standard Input
static UniWriter out
          This field is pre-connected to Standard Output
static java.lang.String workingDir
          The working directory for File I/O.
 
Method Summary
static java.lang.String format(boolean value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static java.lang.String format(byte value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static java.lang.String format(char value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static java.lang.String format(double value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static java.lang.String format(float value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static java.lang.String format(int value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static java.lang.String format(long value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static java.lang.String format(java.lang.Object value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static java.lang.String format(short value, java.lang.String fd)
          Format the passed value using the passed format descriptor and return the result as a string.
static UniPanel getNewUniPanel(java.lang.String title)
          Create a new panel, place it in a new frame, and return a reference to it.
static UniPanel getUniPanel()
          Return the graphics panel (lower pane) of UniCon.
static java.lang.String launch(java.lang.String app, java.lang.String input)
          Launch the indicated app, pass the indicated string to its standard input, and capture (and return) its standard output.
static void print(boolean value)
          Output to the standard output device the literal true if the passed value is true and output false otherwise.
static void print(boolean value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor.
static void print(byte value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor.
static void print(char value)
          Output the passed value to the standard output device.
static void print(char value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor.
static void print(double value)
          Output the passed value to the standard output device.
static void print(double value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor.
static void print(float value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor.
static void print(int value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor.
static void print(long value)
          Output the passed value to the standard output device.
static void print(long value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor.
static void print(java.lang.Object value)
          Output the string representation of the passed object reference to the standard output device.
static void print(java.lang.Object value, java.lang.String fd)
          Output to the string representation of the passed object reference to the standard output device using the passed format descriptor.
static void print(short value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor.
static void println()
          Output the End-Of-Line marker to the standard output device.
static void println(boolean value)
          Output to the standard output device the literal true if the passed value is true and output false otherwise.
static void println(boolean value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void println(byte value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void println(char value)
          Output the passed value to the standard output device followed by an End-Of-Line marker.
static void println(char value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void println(double value)
          Output the passed value to the standard output device followed by an End-Of-Line marker.
static void println(double value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void println(float value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void println(int value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void println(long value)
          Output the passed value to the standard output device followed by an End-Of-Line marker.
static void println(long value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void println(java.lang.Object value)
          Output the string representation of the passed object reference to the standard output device followed by an End-Of-Line marker.
static void println(java.lang.Object value, java.lang.String fd)
          Output to the string representation of the passed object reference to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void println(short value, java.lang.String fd)
          Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.
static void printObject(java.lang.Object value, java.lang.String fileName)
          Output the object whose reference is passed to the passed file.
static boolean readBoolean()
          Read an entire line from the user and return the entered boolean.
static byte readByte()
          Read an entire line from the user and return the entered byte.
static char readChar()
          Read an entire line from the user and return the entered character.
static double readDouble()
          Read an entire line from the user and return the entered double.
static float readFloat()
          Read an entire line from the user and return the entered float.
static int readInt()
          Read an entire line from the user and return the entered int.
static java.lang.String readLine()
          Read and return an entire line from the user.
static long readLong()
          Read an entire line from the user and return the entered long.
static java.lang.Object readObject(java.lang.String fileName)
          Attempt to read and return the object stored in the passed file.
static short readShort()
          Read an entire line from the user and return the entered short.
static java.lang.String repeat(int count, char c)
          Create a string by repeating the passed character the specified number of times.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

public static UniReader in
This field is pre-connected to Standard Input


out

public static UniWriter out
This field is pre-connected to Standard Output


fillChar

public static char fillChar
This field specifies the character to use for padding. The default is space. When the format descriptor specifies a width that is larger than the width of the data being formatted, copies of this fill character are inserted before, after, or before and after the data (depending on right, left, or centre alignment) to pad it to the desired width.


workingDir

public static java.lang.String workingDir
The working directory for File I/O. For all file I/O methods in this package, a file path that is not absolute is considered relative to the directory specified by this field. The default value of this field is the directory that was current when the application was started; i.e. the current directory of the O/S or UniCon. If you plan to change this field then note that no checking is done to verify that the directory exists. If it doesn't, an exception will be thrown when a file I/O is invoked with a relative path in its file name parameter.

Method Detail

getUniPanel

public static UniPanel getUniPanel()
Return the graphics panel (lower pane) of UniCon. The panel is first cleared to the background color and then returned. It is recommended that the pane is sized in UniCon (by dragging the tab separator) as needed before invoking this method so that the desired size is cleared.

If you prefer to obtain a brand new panel, or if your app will run outside UniCon, then use getNewUniPanel(java.lang.String) instead.

Returns:
UniCon's graphics panel to be used for drawing. The return is null if the method is invoked from outside UniCon.

getNewUniPanel

public static UniPanel getNewUniPanel(java.lang.String title)
Create a new panel, place it in a new frame, and return a reference to it. The created frame has the passed title and it can be disposed by closing.

If your app will run within UniCon and prefer to obtain a reference to UniCon's built-in pane, use getUniPanel() instead.

Parameters:
title - the title (caption) of the created fame.
Returns:
a reference to the created panel.

launch

public static java.lang.String launch(java.lang.String app,
                                      java.lang.String input)
Launch the indicated app, pass the indicated string to its standard input, and capture (and return) its standard output. This method facilitates the creation of a harness to test the output of apps (as opposed to the return of methods). When the app is running, its standard output is inhibited (captured but not displayed) and its standard error (if any) is discarded. For example, the following line invokes the app Compute whose class resides in the c:\harness directory and passes 3 and 4 to its standard input:
String output = IO.launch("c:\\harness\\Compute", "3\n4\n");
If the app resides on the classpath, e.g. in the current working directory, then its name does not have to be qualified.

Parameters:
app - the name of the application's class (without the .class extension). If the app does not reside on the classpath then its name must be preceded by an absolute path (using \ or / as separator). The contract here is that the class must have a static main method, and the app.class file must exist either on the classpath or in the indicated path.
input - the input string to be passed to the app's standard input. The input must be suffixed by \n to emulate pressing the ENTER key. If the app expects several inputs, then suffix each by \n and concatenate before passing to this method.
Returns:
the standard output of the app. The returned string represents a concatenation of all the output lines generated by the app (each suffixed by \n).
Throws:
java.lang.RuntimeException - if the app could not be launched, if it required more, or consumed less, input than supplied, or if it caused a runtime error. Inspect the exception's message to determine the exact cause.

repeat

public static java.lang.String repeat(int count,
                                      char c)
Create a string by repeating the passed character the specified number of times. If count is less than 1, a zero-length string is returned.

Parameters:
count - the number of repetitions.
c - the character to be repeated.
Returns:
a string containing count repetitions of c.

format

public static java.lang.String format(byte value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string.

format

public static java.lang.String format(short value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string.

format

public static java.lang.String format(char value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string.

format

public static java.lang.String format(int value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string.

format

public static java.lang.String format(long value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string.

format

public static java.lang.String format(float value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string.

format

public static java.lang.String format(double value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string.

format

public static java.lang.String format(boolean value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string. If the passed value is true, the word true (otherwise false) is returned.

format

public static java.lang.String format(java.lang.Object value,
                                      java.lang.String fd)
Format the passed value using the passed format descriptor and return the result as a string.

Parameters:
value - the value to be formatted.
fd - the format descriptor. (Details.)
Returns:
the formatted value as a string.

readChar

public static char readChar()
Read an entire line from the user and return the entered character. The line must contain exactly one character.

Returns:
the read character as a char.
Throws:
java.lang.RuntimeException - with message: Type Mismatch! if the entered line contains zero, or more than one, character.

readByte

public static byte readByte()
Read an entire line from the user and return the entered byte. Aside from leading/trailing whitespace, the entered line must be made up of digits, optionally preceded by a sign, and must have a numeric value within the range of byte.

Returns:
the byte value of the entry.
Throws:
java.lang.NumberFormatException - if the entry does not represent a byte.

readShort

public static short readShort()
Read an entire line from the user and return the entered short. Aside from leading/trailing whitespace, the entered line must be made up of digits, optionally preceded by a sign, and must have a numeric value within the range of short.

Returns:
the short value of the entry.
Throws:
java.lang.NumberFormatException - if the entry does not represent a short.

readInt

public static int readInt()
Read an entire line from the user and return the entered int. Aside from leading/trailing whitespace, the entered line must be made up of digits, optionally preceded by a sign, and must have a numeric value within the range of int.

Returns:
the int value of the entry.
Throws:
java.lang.NumberFormatException - if the entry does not represent an int.

readLong

public static long readLong()
Read an entire line from the user and return the entered long. Aside from leading/trailing whitespace, the entered line must be made up of digits, optionally preceded by a sign, and must have a numeric value within the range of long.

Returns:
the long value of the entry.
Throws:
java.lang.NumberFormatException - if the entry does not represent a long.

readFloat

public static float readFloat()
Read an entire line from the user and return the entered float. Aside from leading/trailing whitespace, the entered line must be made up of digits, optionally preceded by a sign, a decimal point, an optional exponent prefixed by the letter E or e, and must have a numeric value within the range of float.

Returns:
the float value of the entry.
Throws:
java.lang.NumberFormatException - if the entry does not represent a float.

readDouble

public static double readDouble()
Read an entire line from the user and return the entered double. Aside from leading/trailing whitespace, the entered line must be made up of digits, optionally preceded by a sign, a decimal point, an optional exponent prefixed by the letter E or e, and must have a numeric value within the range of double.

Returns:
the double value of the entry.
Throws:
java.lang.NumberFormatException - if the entry does not represent a double.

readBoolean

public static boolean readBoolean()
Read an entire line from the user and return the entered boolean.

Returns:
true if, aside from leading / trailing whitespace, the entry is the literal true (case-insensitive). false is returned otherwise.

readLine

public static java.lang.String readLine()
Read and return an entire line from the user.

Returns:
the read line, excluding the EOL marker, as a String.

println

public static void println()
Output the End-Of-Line marker to the standard output device. This is typically used to output an empty line.


print

public static void print(char value)
Output the passed value to the standard output device. No trailing End-Of-Line character is printed.

Parameters:
value - the value to be printed.

println

public static void println(char value)
Output the passed value to the standard output device followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.

print

public static void print(long value)
Output the passed value to the standard output device. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed (its type can be byte, short, int or long).

println

public static void println(long value)
Output the passed value to the standard output device followed by an End-Of-Line marker.

Parameters:
value - the value to be printed (its type can be byte, short, int or long).

print

public static void print(double value)
Output the passed value to the standard output device. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed (its type can be float or double).

println

public static void println(double value)
Output the passed value to the standard output device followed by an End-Of-Line marker.

Parameters:
value - the value to be printed (its type can be float or double).

print

public static void print(boolean value)
Output to the standard output device the literal true if the passed value is true and output false otherwise. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.

println

public static void println(boolean value)
Output to the standard output device the literal true if the passed value is true and output false otherwise. The output is followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.

print

public static void print(java.lang.Object value)
Output the string representation of the passed object reference to the standard output device. No trailing End-Of-Line marker is printed. If the reference is null, the string "" is printed.

Parameters:
value - the value to be printed.

println

public static void println(java.lang.Object value)
Output the string representation of the passed object reference to the standard output device followed by an End-Of-Line marker. If the reference is null, the string "" is printed.

Parameters:
value - the value to be printed.

print

public static void print(byte value,
                         java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor
See Also:
format(byte, String)

println

public static void println(byte value,
                           java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(byte, String)

print

public static void print(short value,
                         java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(short, String)

println

public static void println(short value,
                           java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(short, String)

print

public static void print(char value,
                         java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(char, String)

println

public static void println(char value,
                           java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(char, String)

print

public static void print(int value,
                         java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(int, String)

println

public static void println(int value,
                           java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(int, String)

print

public static void print(long value,
                         java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(long, String)

println

public static void println(long value,
                           java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(long, String)

print

public static void print(float value,
                         java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(float, String)

println

public static void println(float value,
                           java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(float, String)

print

public static void print(double value,
                         java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(double, String)

println

public static void println(double value,
                           java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(double, String)

print

public static void print(boolean value,
                         java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(boolean, String)

println

public static void println(boolean value,
                           java.lang.String fd)
Output the passed value to the standard output device using the passed format descriptor and followed by an End-Of-Line marker.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(boolean, String)

print

public static void print(java.lang.Object value,
                         java.lang.String fd)
Output to the string representation of the passed object reference to the standard output device using the passed format descriptor. No trailing End-Of-Line marker is printed. If the reference is null, the string "" is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(Object, String)

println

public static void println(java.lang.Object value,
                           java.lang.String fd)
Output to the string representation of the passed object reference to the standard output device using the passed format descriptor and followed by an End-Of-Line marker. If the reference is null, the string "" is printed.

Parameters:
value - the value to be printed.
fd - the format descriptor. (Details.)
See Also:
format(Object, String)

readObject

public static java.lang.Object readObject(java.lang.String fileName)
Attempt to read and return the object stored in the passed file. The object must have been written to the source by the writeObject method.

Parameters:
fileName - the name of the file to read from. If the embedded path is relative then it is considered relative to the workingDir.
Throws:
a - runtime exception if the file does not exist, is corrupt, or does not contain a serialized object.

printObject

public static void printObject(java.lang.Object value,
                               java.lang.String fileName)
Output the object whose reference is passed to the passed file. All non-static features of the object, and recursively any object referenced by it, are captured so that all these objects can be re-instantiated later through the readObject method. Note that only objects that implement the java.io.Serializable interface are captured.

Parameters:
value - a reference to the object to be written.
fileName - the name of the file to write on. If the file already exists, it will be deleted; i.e. overwritten; otherwise it will be created. If the embedded path is relative then it is considered relative to the workingDir.
Throws:
java.io.NotSerializableException - if the passed object does not implement java.io.Serializable.
java.lang.RuntimeException - with message: File cannot be written to if the file name is not accepted by the operating system or if the disk is write-protected.


Java by Abstraction: A Client-View Approach