少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

package com.abin.lee.servlet.important.type;

import java.io.Serializable;

public class LookValue implements Serializable{
 /**
  *
  */
 private static final long serialVersionUID = -7746631577693804188L;
 private int id;
 private String name;
 private transient String status;
 
 public LookValue() {
  super();
 }
 public LookValue(int id, String name, String status) {
  super();
  this.id = id;
  this.name = name;
  this.status = status;
 }
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getStatus() {
  return status;
 }
 public void setStatus(String status) {
  this.status = status;
 }
 
}





package com.abin.lee.servlet.important.type.test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import org.junit.Test;

import com.abin.lee.servlet.important.type.LookValue;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;

public class LookValueTest {
 @Test
 public void testLookValue() throws IOException, ClassNotFoundException{
  LookValue look=new LookValue();
  look.setId(1);
  look.setName("abin");
  look.setStatus("abing");
  OutputStream out=new ByteOutputStream();
  FileOutputStream file=new FileOutputStream("data.ser");
  ObjectOutputStream obj=new ObjectOutputStream(file);
  obj.writeObject(look);
  obj.flush();
  obj.close();
  
  look=null;
  FileInputStream input=new FileInputStream("data.ser");
  ObjectInputStream oin=new ObjectInputStream(input);
  look=(LookValue)oin.readObject();
  oin.close();
  System.out.println("id="+look.getId());
  System.out.println("Name="+look.getName());
  System.out.println("Status="+look.getStatus());
 }
}




输出结果:
id=1
Name=abin
Status=null
posted on 2012-10-08 21:49 abin 阅读(747) 评论(0)  编辑  收藏 所属分类: java基础知识

只有注册用户登录后才能发表评论。


网站导航: