首页 > 编程语言 > 详细

java序列化

时间:2015-07-19 23:18:13      阅读:129      评论:0      收藏:0      [点我收藏+]
public class Test6 implements Serializable{
	private static final long serialUID = 1L;
	private Date loggingDate = new Date();
	private String uid ;
	private transient String pwd ;
	
	Test6(String user ,String pwd ){
		this.uid = user ;
		this.pwd = pwd; 
	}
	
	public String toString (){
		String password = null ;
		if (pwd== null){
			password = "NOT SET";
		}else {
			password = pwd;
		}
		return "logon info:"+uid+","+password;
	}
	public static void main(String [] args){
		Test6 logInfo = new Test6("lsj", "12345");
		System.out.println(logInfo.toString()) ;
		
		try {
			ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("logInfo.out"));
			os.writeObject(logInfo);
			os.close() ;
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		try {
			ObjectInputStream is = new ObjectInputStream(new FileInputStream("logInfo.out"));
			Test6 logInfo1= (Test6) is.readObject();
			System.out.println(logInfo1.toString());
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

}

 结果

logon info:lsj,12345
logon info:lsj,NOT SET

java序列化

原文:http://www.cnblogs.com/chuiyuan/p/4659954.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!