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 墻頭草 閱讀(596) 評論(0)  編輯  收藏

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


          網(wǎng)站導航:
           
          人人游戲網(wǎng) 軟件開發(fā)網(wǎng) 貨運專家
          主站蜘蛛池模板: 金寨县| 腾冲县| 东乌珠穆沁旗| 丰都县| 应城市| 宁国市| 海阳市| 崇信县| 习水县| 百色市| 东平县| 确山县| 虎林市| 外汇| 金川县| 灌云县| 玉门市| 武穴市| 长岭县| 宾川县| 怀宁县| 星座| 凤凰县| 疏勒县| 竹山县| 静宁县| 买车| 库尔勒市| 舒城县| 临桂县| 师宗县| 洛隆县| 沿河| 兴和县| 阿尔山市| 沙雅县| 彭山县| 分宜县| 扎兰屯市| 贵定县| 安福县|