显然吗,你没有处理异常,加上try catch就可以了

解决方案 »

  1.   

    请问为什么是7890呢?file.seek(5); 主要指什么?请细说!
      

  2.   

    import java.io.*;public class TestIPApp {
    public static void main(String args[]) {
    try{
            RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
            file.writeBoolean(true);
            file.writeInt(123456);
            file.writeInt(7890);
            file.writeLong(1000000);
            file.writeInt(777);
            file.writeFloat(.0001f);
            file.seek(5);
            System.out.println(file.readInt());
            file.close();
        }catch (IOException e){ }
    }
    }结果:7890
      

  3.   

    请问为什么是7890呢?file.seek(5); 主要指什么?请细说!
      

  4.   

    请看API的简单解释,seek的功能是设置filepointer(文件指针)的绝对位置.seek(long pos):
      
    Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.至于为什么是5,估计
    boolean值 1个字节(我猜的哦:-)
    int值 4个字节 (这个是固定的)
    所以,设置seek(5)之后,就把filepointer设置到了int 7890的位置