testcustom.java

来自「java应用开发详解」· Java 代码 · 共 27 行

JAVA
27
字号
import java.io.*;

class testCustom
{
   public static void main( String args[] ) throws Exception 
   {
      serialize();
      deserialize();
   }
      
   public static void serialize() throws Exception 
   {
      OutputStream outputFile = new FileOutputStream( "SerializedCustom" );
      ObjectOutputStream cout = new ObjectOutputStream( outputFile );
      cout.writeObject( new custom2( 12));
      cout.close();
   }   
   
   public static void deserialize() throws Exception 
   {
      InputStream inputFile = new FileInputStream( "SerializedCustom" );
      ObjectInputStream cin = new ObjectInputStream( inputFile );
      custom2 test = (custom2) cin.readObject();
      System.out.println( test.toString() );
   }
}

⌨️ 快捷键说明

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