0
我試圖從流中讀取一個對象ChatMassage
,並使用其方法getMassage()
打印一條消息(該對象包含該消息)。它首次打印一條消息,但下一次總是打印第一條消息。哪裏不對?從流中讀取對象
下面是代碼示例:
while(keepGoing){
System.out.println("Client: " + ((ChatMassage) in.readObject()).getMassage() + "\n");
}
ChatMassage類:
public class ChatMassage implements Serializable {
String msg, recipientName = null;
String senderName = "None";
public void setMassage(String msg) {
this.msg = msg;
}
public void setRecipientName(String recName) {
recipientName = recName;
}
public String getMassage() {
return msg;
}
public String getRecipientName() {
return recipientName;
}
public void setSenderName(String name) {
senderName = name;
}
public String getSenderName() {
return senderName;
}
}