JDK的说明看不太懂。int是四个字节的

解决方案 »

  1.   

    你可以进到readInt()方法里面看一下
        public final int readInt() throws IOException {
    int ch1 = this.read();
    int ch2 = this.read();
    int ch3 = this.read();
    int ch4 = this.read();
    if ((ch1 | ch2 | ch3 | ch4) < 0)
        throw new EOFException();
    return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
        }Reads a byte of data from this file.
    public native int read() throws IOException;本质上还是一个一个的读字节,然后通过位移运算把这些字节按java语言所规定的高低位进行调整计算出来的
      

  2.   

    public final int readInt()
                      throws IOException从此文件读取一个有符号的 32 位整数。此方法从该文件的当前文件指针开始读取 4 个字节。如果按顺序读取的字节为 b1、b2、b3 和 b4,其中 0 <= b1, b2, b3, b4 <= 255,则结果将等于: 
    (b1 << 24) | (b2 << 16) + (b3 << 8) + b4
      

  3.   

    这个不需要判断的啊,你调用readInt时,它就按照读取int的方式来读的。
    DataInputStream里的readInt时格式是这样的[int的长度][int数字的值]