We can see the dataoutputstream implementation in the D:/jdk1.5.0/src/Java/IO source code package: Public final void writeshort (INT v) throws ioexception { Out. write (v >>> 8) & 0xFF ); Out. write (v >>> 0) & 0xFF ); IncCount (2 ); } Public final void writeInt (int v) throws IOException { Out. write (v >>> 24) & 0xFF ); Out. write (v >>> 16) & 0xFF ); Out. write (v >>> 8) & 0xFF ); Out. write (v >>> 0) & 0xFF ); IncCount (4 ); } Public final void writeLong (long v) throws IOException { WriteBuffer [0] = (byte) (v >>> 56 ); WriteBuffer [1] = (byte) (v >>> 48 ); WriteBuffer [2] = (byte) (v >>> 40 ); WriteBuffer [3] = (byte) (v >>> 32 ); WriteBuffer [4] = (byte) (v >>> 24 ); WriteBuffer [5] = (byte) (v >>> 16 ); WriteBuffer [6] = (byte) (v >>> 8 ); WriteBuffer [7] = (byte) (v >>> 0 ); Out. write (writeBuffer, 0, 8 ); IncCount (8 ); } Public final void writeChar (int v) throws IOException { Out. write (v >>> 8) & 0xFF ); Out. write (v >>> 0) & 0xFF ); IncCount (2 ); } As you can see, the writeChar () method of this class occupies two bytes, Because Java is Unicode. If you are communicating with the java server, there will be no problems. However, if you are communicating with the C/C ++ server, problems may occur. In addition, the long type in this class is written into 8 bytes. Therefore, if your server is not written in java, it is best not to call methods in this class for communication. |