Discussion of Activity 4.3 - Writing a date-stamp to a text file

Here is our sample solution for the class DateStamper:

import java.io.*;
public class DateStamper
{
   private PrintWriter pw;
   
   public void openStreams(String filename) throws IOException
   {
      pw = new PrintWriter(filename);
   }
   public void run(String filename) throws IOException
   {
      // Open output streams.
      openStreams(filename);
      // Create new DateStamp.
      String stamp = DateStamp.getFullDate();
      System.out.println("File " + filename +
         " will be date-stamped " + stamp);
      pw.println("This file date-stamped " + stamp);
      // Close output streams.
      closeStreams();
   }
   public void closeStreams() throws IOException
   {
      pw.close();
   }
}