Socket PrintWriterでのwrite()とprint()の違い
try {
PrintWriter pw = response.getWriter();
int x = 98;
pw.write(x);
pw.print(x);
} catch (IOException e) {
e.printStackTrace();
}
出力:b 98
最終的には抽象クラスWriterのwriteメソッドprintメソッドを書き換えて様々なタイプのデータを文字列に変換して出力することができます.リロードされたwriteメソッドは、文字、文字配列、文字列などの文字に関連するデータしか出力できません.ソースコード(java.io.PrintWriter)を確認します.
1:writeメソッド:
public void write(int c) {
synchronized (lock) {
out.write(c);
}
Thread.currentThread().interrupt();
catch (IOException x) {
}
2:printメソッド:
view plain copy to clipboard print ?
public void print(int i) {
}