对象怎样序列化呀!!急急!!

chenhagi_0 2004-11-21 08:10:55
我想问大哥,大姐一个问题,怎样实现对象的序列化!能不能给个例子,谢了!!分高哟
...全文
135 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
beakham 2004-11-22
  • 打赏
  • 举报
回复
实现Serializable
classjava 2004-11-21
  • 打赏
  • 举报
回复
import java.io.Serializable;
public class Test implements Serializable()
{ int i=0;
public static void main(String[] args)
{ new Test();
}
}
这就是啦
JaredJared 2004-11-21
  • 打赏
  • 举报
回复
import java.io.Serializable;
public class Player implements Serializable {
private int id;
private String nick;
private String password;
private String gender;
private String email;
private int score = 0;
private int grade = 0;
private int totalAmount = 0;
private String regDate;

public Player() {}

public Player(int id, String pass) {
this.id = id;
this.password = pass;
}

public Player(String name, String pass, String gender, String email) {
this.nick = name;
this.gender = gender;
this.password = pass;
this.email = email;
}

public Player(int id, String name, String pass, String gender, String email, int s, int g, int t, String r) {
this(name, pass, gender, email);
this.id = id;
this.score = s;
this.grade = g;
this.totalAmount = t;
this.regDate = r;
}

public Player(Player player) {
this.id = player.id;
this.nick = new String(player.nick);
this.password = new String(player.password);
this.gender = new String(player.gender);
this.email = new String(player.email);
this.score = player.score;
this.grade = player.grade;
this.totalAmount = player.totalAmount;
this.regDate = new String(player.regDate);
}

public String toString() {
String str;
str = "用户帐号: " + id;
str += "\n昵称: " + nick;
str += "\n密码:" + "******";
str += "\n性别:" + gender;
str += "\nE-mail:" + email;
str += "\n积分:" + score + " 等级:" + grade + " 对弈场数:" + totalAmount;
str += "\n注册日期:" + regDate;
return str;
}

public String getEmail() {
return email;
}


public int getGrade() {
return grade;
}


public String getGender() {
return gender;
}


public int getId() {
return id;
}


public int getTotalAmount() {
return totalAmount;
}


public String getNick() {
return nick;
}


public String getPassword() {
return password;
}


public int getScore() {
return score;
}


public void setEmail(String string) {
email = string;
}


public void setGrade(int i) {
grade = i;
}

public void setGender(String string) {
gender = string;
}

public void setId(int i) {
id = i;
}

public void setTotalAmount(int i) {
totalAmount = i;
}

public void setNick(String string) {
nick = string;
}

public void setPassword(String string) {
password = string;
}

public void setScore(int i) {
score = i;
}

public String getRegDate() {
return regDate;
}

}
funcreal 2004-11-21
  • 打赏
  • 举报
回复
实现Serializable即可。这个接口没有任何方法。
jFresH_MaN 2004-11-21
  • 打赏
  • 举报
回复
class test implements java.io.Serializable{
//......
}
JaredJared 2004-11-21
  • 打赏
  • 举报
回复
实现Serializable 接口就可以了!
sjg008 2004-11-21
  • 打赏
  • 举报
回复
帮你顶一下

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧