【发布时间】:2013-09-23 11:32:27
【问题描述】:
我想以 UTF-8 格式存储数据。数据可以由任何原始类型和字符串表示(标准DataOutput API)。每个数据记录由“记录分隔符”符号分隔(ASCII int - 30,hex - 1E)。如何解决读取这个特殊字符的问题?案例:
- 我正在写字符串,我可以正确读取这个字符,没有问题。
- 我正在写整数。 (int)30 和 (special char)30 之间的值 30 应该如何区分?
【问题讨论】:
-
你查过UTF-8编码表了吗? utf8-chartable.de
-
即使我将其存储为:
ByteBuffer buffer = ByteBuffer.allocate(N); buffer.order(ByteOrder.BIG_ENDIAN); buffer.put(Integer.toHexString(30).getBytes()); // end of record byte[] bytes = buffer.array(); dataOutput.write(bytes); Still can be read as int by dataInput.readInt(); // 828702720
标签: java encoding utf-8 special-characters