分享java的Serializable功能

可以将java对象序列化为文件,也可以将文件反序列化为java对象

地址:分享java的Serializable功能  代码:http://www.zuidaima.com/share/1550463266802688.htm

 

package com.zuidaima.util.file;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

/**
 * 序列化java对象到文件
 * 
 * @author www.zuidaima.com
 * 
 */
public class SerializeObject2File {

	public static void main(String args[]) {
		serializeAddress("www.zuidaima.com", "zuidaima");
	}

	public static void serializeAddress(String street, String country) {

		Address address = new Address();
		address.setStreet(street);
		address.setCountry(country);

		try {

			FileOutputStream fout = new FileOutputStream("c:\\zuidaima_com.ser");
			ObjectOutputStream oos = new ObjectOutputStream(fout);
			oos.writeObject(address);
			oos.close();
			System.out.println("Done");

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}

	    			

 

 

分享java的Serializable功能

标签: java 序列化 Serializable话题: 语言基础 脚本和工具

 

 

你可能感兴趣的:(java,Serializable,序列化)