example8_11.java

来自「书中的例题」· Java 代码 · 共 40 行

JAVA
40
字号
import java.io.*;
import java.util.*;
class Address implements Serializable
  { 
	  protected String first, email;
      public Address( )
        {  
			first = email = ""; 
		}
      public Address( String _first, String _email )
        {
		  first = _first;
          email = _email;
        }
      public String toString( )
        { 
		  return first + " (" + email + ")" ; 
		}
  }
//主类
  public class Example8_11
    {
	  public static void main( String args[ ] )
        { 
		  try{ 
              FileOutputStream file = new FileOutputStream("test.dat");
              ObjectOutputStream out = new ObjectOutputStream(file);
              Date now = new Date();
              Address address = new Address("abc", "abc@zsm8.com");
             out.writeObject(now);
             out.writeObject(address);
              out.close();
			  System.out.println("ok");
           }
           catch(IOException ioe)
           {  System.out.println(ioe); }
         }
   }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?