Listing 1: LogFile.java — A class for writing log files

import java.io.*;
import java.util.*;

class LogFile
{
    String fileName;

    public LogFile(String fileName)
    {
        this.fileName = fileName;
    }

    public void log(String message)
        throws IOException
    {
        FileWriter file =
            new FileWriter(fileName, true);
        BufferedWriter w =
            new BufferedWriter(file);
        w.write(new Date() + ": ");
        w.write(message);
        w.newLine();
        w.close();
    }

    public void 
    log(String prefix, String message)
        throws IOException
    {
        log(prefix + ": " + message);
    }
}
— End of Listing —