001package edu.pdx.cs410J.core; 002 003import java.io.FileInputStream; 004import java.io.IOException; 005import java.io.ObjectInputStream; 006import java.util.Date; 007 008/** 009 * This class demonstrates object serialization by reading an instance 010 * of <code>Date</code> from a file. 011 */ 012public class ReadDate { 013 014 /** 015 * Read a <code>Date</code> instance from th file whose name is 016 * specified on the command line. 017 */ 018 public static void main(String[] args) { 019 String fileName = args[0]; 020 021 Date date = null; 022 try { 023 FileInputStream fis = new FileInputStream(fileName); 024 ObjectInputStream in = new ObjectInputStream(fis); 025 date = (Date) in.readObject(); 026 in.close(); 027 System.out.println("Read " + date); 028 029 } catch (ClassNotFoundException ex) { 030 System.err.println("** No class " + ex); 031 System.exit(1); 032 033 } catch (IOException ex) { 034 System.err.println("**IOException: " + ex); 035 System.exit(1); 036 } 037 } 038 039}