0
爲什麼這裏的代碼是從messageBox
域獲得消息後使用PrintWriter
類的flush()
方法....?我無法理解,爲什麼要使用PrintWriter類的flush()方法?
public void connectToSocket() {
try {
Socket socket = new Socket("localhost", 80);
PrintWriter writer = new PrintWriter(socket.getOutputStream);
System.out.println("Connected Successfully");
}
catch(IOException ex) {
ex.printStackTrace();
}
}
public class sendMessageListener implements ActionListener {
try {
writer.println(messageBox.getText());
writer.flush();
}
catch(IOException ex) {
ex.printStackTrace();
}
}
刷新緩衝區。你有沒有考慮閱讀Javadoc? – EJP