【发布时间】:2023-03-27 04:12:01
【问题描述】:
有没有更优雅的方法从 ByteBuffer 读取四个字节并将每个字节视为一个 char(而不是每对都作为一个 char)然后这个,我相信一定有一个更简洁的方法。
public static String read4Chars(ByteBuffer bytes) throws IOException
{
StringBuffer sbuf = new StringBuffer(4);
for (int i = 0; i < 4; i++) {
char ch = (char) bytes.get();
sbuf.append(ch);
}
return sbuf.toString();
}
【问题讨论】:
-
没有每个字节代表一个ASCII字符