writeChars
public final void writeChars(String s)
throws IOException
Writes a string to the underlying output stream as a sequence of characters. Each character is written to the data output stream as if by the writeChar method. If no exception is thrown, the counter written is incremented by twice the length of s.
Specified by:
writeChars in interface DataOutput
Parameters:
s - a String value to be written.
Throws:
IOException - if an I/O error occurs.
See Also:
writeChar(int), FilterOutputStream.out
上面是jdk文档中对writeChars的解释其中提到“Each character is written to the data output stream as if by the writeChar method ”,即 每个字符同方法writeChar一样被写入数据输出流,所以应该查看方法writeChar。
下面来看jdk文档中对writeChar的说明
writeChar
public final void writeChar(int v)
throws IOException
Writes a char to the underlying output stream as a 2-byte value, high byte first. If no exception is thrown, the counter written is incremented by 2.
Specified by:
writeChar in interface DataOutput
Parameters:
v - a char value to be written.
Throws:
IOException - if an I/O error occurs.
See Also:
FilterOutputStream.out
其中提到“Writes a char to the underlying output stream as a 2-byte value, high byte first”,即将一个字符以高位字节优先的双字节(big endian)的形式写入下面的输出流。
BIG ENDIAN:最低位地址存放高位字节,可称高位优先,内存从最低地址开始按顺序存放(高数位数字先写)。最高位字节放最前面。
LITTLE ENDIAN:最低位地址存放低位字节,可称低位优先,内存从最低地址开始按顺序存放(低数位数字先写)。最低位字节放最前面。
希望我的 回答对你有帮助。 |