java序列化
2015-07-19 22:04
302 查看
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
相关文章推荐
- 精选30道Java笔试题解答
- Java多线程实现生产者消费者延伸问题
- Java中的代码块
- JAVA基础_Date,Calender应用
- Java中HashMap,LinkedHashMap,TreeMap的区别
- spring单例bean实现原理
- spring入门教程——笔记
- JAVA程序 通过IP地址 获取MAC地址
- Java中线程的操作
- 深入理解 Java 垃圾回收机制
- [LeetCode][Java] Gray Code
- eclipse 中添加工程 Some projects cannot be imported because they already exist in the workspace
- myeclipse自动补全的设置
- javaee 集锦
- java 帮助文档API下载地址
- Java的Swing入门,继承JFrame报错问题
- 感知哈希算法的java实现
- JAVA_SE基础——20.数组的常见操作
- Spring 注解 @Resource和@Autowired
- Java HashMap的工作原理