⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cloneinvoices.java

📁 21天学通java的示例程序源代码
💻 JAVA
字号:
package com.wrox.clone;
import java.io.*;

public class CloneInvoices {
  public static void main(String[] args) {
    try {
      InvoiceItems oInvoiceItems = new InvoiceItems();

      // Add an invoice;
      oInvoiceItems.addInvoice(new InvoiceItem("Widget", 1, 1.00F));

      // Create a Memory I/O Stream to hold the serialized InvoiceItems object;
      ByteArrayOutputStream oByteArrayOutputStream =
        new ByteArrayOutputStream();

      // Serialize the InvoiceItems object and its contents;
      ObjectOutputStream oObjectOutputStream =
        new ObjectOutputStream(oByteArrayOutputStream);
      oObjectOutputStream.writeObject(oInvoiceItems);

      // Save the byte array stream;
      byte[] bSerializedObject = oByteArrayOutputStream.toByteArray();

      // Release the reference to the InvoiceItems object;
      oInvoiceItems = null;

      // Create a Memory I/O Stream to restore the serialized
      // InvoiceItems object;
      ByteArrayInputStream oByteArrayInputStream =
        new ByteArrayInputStream(bSerializedObject);

      // Restore the InvoiceItems object and its contents;
      ObjectInputStream oObjectInputStream =
        new ObjectInputStream(oByteArrayInputStream);
      oInvoiceItems = (InvoiceItems) oObjectInputStream.readObject();

      // Write the details to System.out to confirm the clone was restored;
      InvoiceItem oInvoiceItem = oInvoiceItems.getInvoice();
      oInvoiceItem.printInvoice();
    } catch (IOException e1) {}
    catch (ClassNotFoundException e2) {}
  }
}

⌨️ 快捷键说明

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