posts - 241,  comments - 116,  trackbacks - 0
          transient說明一個屬性是臨時的,不會被序列化。
          下面是一個Demo,name聲明為 transient,不被序列化
          package com.zzs.tet;

          import java.io.File;
          import java.io.FileInputStream;JDK源代碼之LinkedList類分析
          import java.io.FileNotFoundException;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.ObjectInput;
          import java.io.ObjectInputStream;
          import java.io.ObjectOutput;
          import java.io.ObjectOutputStream;
          import java.io.Serializable;

          public class TransientDemo implements Serializable{
              /**
               *
               */
              private static final long serialVersionUID = 1L;
              private  transient String name;
              private String password;
              
              public String getName() {
                  return name;
              }

              public void setName(String name) {
                  this.name = name;
              }

              public String getPassword() {
                  return password;
              }

              public void setPassword(String password) {
                  this.password = password;
              }

              /**
               * @param args
               * @throws IOException
               * @throws FileNotFoundException
               * @throws ClassNotFoundException
               */
              public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
                  // TODO Auto-generated method stub
                  String path="D:"+File.separator+"object.txt";
                  File file=new File(path);
                  TransientDemo transientDemo=new TransientDemo();
                  transientDemo.setName("姓名");
                  transientDemo.setPassword("密碼");
                  ObjectOutput output=new ObjectOutputStream(new FileOutputStream(file));
                  output.writeObject(transientDemo);
                  ObjectInput input=new ObjectInputStream(new FileInputStream(file));
                  TransientDemo demo=(    TransientDemo )input.readObject();
                  System.out.println(demo.getName()+demo.getPassword());
              }

          }
          posted on 2011-07-26 09:29 墻頭草 閱讀(600) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          人人游戲網 軟件開發網 貨運專家
          主站蜘蛛池模板: 紫金县| 镇康县| 江门市| 克东县| 永平县| 舟曲县| 松桃| 舞钢市| 车致| 浦城县| 应用必备| 东乌珠穆沁旗| 南华县| 武清区| 渭源县| 缙云县| 嘉善县| 海城市| 西乌珠穆沁旗| 株洲市| 安庆市| 高平市| 麦盖提县| 团风县| 永定县| 共和县| 驻马店市| 武强县| 井研县| 化隆| 娄底市| 滦南县| 青州市| 彭州市| 土默特左旗| 新野县| 积石山| 新和县| 吐鲁番市| 津南区| 本溪市|