亚洲欧洲国产欧美一区精品,激情五月亚洲色五月,最新精品国偷自产在线婷婷,欧美婷婷丁香五月天社区

      考試首頁 | 考試用書 | 培訓課程 | 模擬考場 | 考試論壇  
      全國  |             |          |          |          |          |         
        當前位置:計算機等級 > 二級考試 > Java語言程序設計 > 考試輔導 > 文章內容
        

      全國計算機等級考試Java語言程序設計輔導(85)

      中華IT學院   【 】  [ 2016年3月10日 ]

      ObjectOutputStream 類用來序列化一個對象,如下的SerializeDemo例子實例化了一個Employee對象,并將該對象序列化到一個文件中。

      該程序執(zhí)行后,就創(chuàng)建了一個名為employee.ser文件。該程序沒有任何輸出,但是你可以通過代碼研讀來理解程序的作用。

      注意: 當序列化一個對象到文件時, 按照Java的標準約定是給文件一個.ser擴展名。

      import java.io.*;
      
      public class SerializeDemo
      {
         public static void main(String [] args)
         {
            Employee e = new Employee();
            e.name = "Reyan Ali";
            e.address = "Phokka Kuan, Ambehta Peer";
            e.SSN = 11122333;
            e.number = 101;
            try
            {
               FileOutputStream fileOut =
               new FileOutputStream("/tmp/employee.ser");
               ObjectOutputStream out = new ObjectOutputStream(fileOut);
               out.writeObject(e);
               out.close();
               fileOut.close();
               System.out.printf("Serialized data is saved in /tmp/employee.ser");
            }catch(IOException i)
            {
                i.printStackTrace();
            }
         }
      }
      分享到:
      本文糾錯】【告訴好友】【打印此文】【返回頂部
      將考試網(wǎng)添加到收藏夾 | 每次上網(wǎng)自動訪問考試網(wǎng) | 復制本頁地址,傳給QQ/MSN上的好友 | 申請鏈接 | 意見留言 TOP
      關于本站  網(wǎng)站聲明  廣告服務  聯(lián)系方式  站內導航  考試論壇
      Copyright © 2007-2013 中華考試網(wǎng)(Examw.com) All Rights Reserved