如何序列化对象数组? 偶一个对象,已经实现了Serializable现在偶想对这个对象的数组序列化,该怎么办? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //实现接口@SuppressWarnings("serial")public class Person implements Serializable { private int id; private String name; public Person() { } public Person(int id, String name) { super(); this.id = id; this.name = name; } 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; }}2.序列化转为数组public class SerializeUtil { /** * 序列化 * * @param object * @return */ public static byte[] serialize(Object object) { ObjectOutputStream oos = null; ByteArrayOutputStream baos = null; try { // 序列化 baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(object); byte[] bytes = baos.toByteArray(); return bytes; } catch (Exception e) { } return null; } 大师 struts2的多种类型转换 Object...args? 此程序的作用是。选择下拉菜单里面的国家。并在两个地方显示国旗和国家介绍。但怎么不能显示。为了测试。我只添加了中国 GridLayout布局的边框如何显示 求助,为什么不能搜出来 如何实现类似qq的表情功能 为什么用javamail连接邮箱出现NoSuchProviderException?怎么没有provider呢?求救 那些是java经典网站?有源程序下载的,谢谢各位!◎!!! jdbc,我怎么找不到jdbc driver? Java界面设计 Object... elements
@SuppressWarnings("serial")
public class Person implements Serializable {
private int id;
private String name; public Person() {
} public Person(int id, String name) {
super();
this.id = id;
this.name = name;
} 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;
}}
2.序列化转为数组public class SerializeUtil {
/**
* 序列化
*
* @param object
* @return
*/
public static byte[] serialize(Object object) {
ObjectOutputStream oos = null;
ByteArrayOutputStream baos = null;
try {
// 序列化
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(object);
byte[] bytes = baos.toByteArray();
return bytes;
} catch (Exception e) { }
return null;
}