[code="java"]public class ByteTester {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(259);//00000000 00000000 00000001 00000011
byte [] buff = out.toByteArray();
out.close();
System.out.println("buff.length:="+buff.length);
ByteArrayInputStream in = new ByteArrayInputStream(buff);
int data;
while((data=in.read())!=-1){
System.out.println(data);
}
in.close();
}[/code]
输出结果:buff.length:=1
3
我初步分析是:out.write 只是写入最低位的一个字节,所以读取出才是3
如果是这样的话,写入了数字259 读取的却是3
java io 通过什么保证写入和读出的是一致的呢