我使用了以下代码。我似乎无法从字节数组中取回 x 的值。这是我的代码:
int seqNo = 0;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bout);
try {
out.writeInt(seqNo);
String i = Integer.toString(seqNo) + "hello";
byte[] b = i.getBytes();
System.out.println(Arrays.toString(b));
int x = b[0];
System.out.println(x);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这是输出:
[48, 104, 101, 108, 108, 111]
48
输出应包含 0 而不是 48。请帮忙
48
是 ASCII 码 0
int x=b[0]-48;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句