我需要從發送到輸出流的所有內容中獲取字節數組。但是,我得到了4個字節的垃圾。爲什麼?ObjectOutputStream.toByteArray返回垃圾
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.write(new byte[]{1,2,3,4,5,6,7,8,9});
byte[] original = byteArrayOutputStream.toByteArray();
System.out.println(Arrays.toString(original)); // why not [1,2,3,4,5,6,7,8,9]?
謝謝。你介意看我的另一個問題嗎? http://stackoverflow.com/questions/12302838/writing-to-the-objectoutputstream-and-getting-rubbish-back – user1651914