001package edu.pdx.cs410J.net; 002 003import java.io.*; 004import java.util.*; 005 006/** 007 * Demonstrates serialization by writing an instance of 008 * <code>Date</code> to a file. 009 */ 010public class WriteDate { 011 012 /** 013 * Writes the <code>Date</code> object for the current day and time 014 * to a file whose name is specified on the command line. 015 */ 016 public static void main(String[] args) { 017 String fileName = args[0]; 018 019 try { 020 FileOutputStream fos = new FileOutputStream(fileName); 021 ObjectOutputStream out = new ObjectOutputStream(fos); 022 Date date = new Date(); 023 System.out.println("Writing " + date); 024 out.writeObject(date); 025 out.flush(); 026 out.close(); 027 028 } catch (IOException ex) { 029 System.err.println("**IOException: " + ex); 030 System.exit(1); 031 } 032 } 033 034}