| 
 
| 当我再添加第二个人时就抛异常:EOFException??、复制代码import java.io.*;
class  RandomAccessFileDemo
{
        public static void main(String[] args)  throws  Exception
        {
                //writeFile();
                readFile();
        }
        public static void readFile()throws IOException
        {
                RandomAccessFile raf = new RandomAccessFile("ran.txt","r");
                //调整指针
                raf.seek(8);
                 byte [] buf = new byte[4];
                 raf.read(buf);
                 String name = new String(buf);
                 int age = raf.readInt();
                 System.out.println("name="+name);
                  System.out.println("age="+age);
                 raf.close();
        }
        public static void writeFile()throws IOException
        {
                RandomAccessFile raf = new RandomAccessFile("ran.txt","rw");
                raf.write("李四".getBytes());
                raf.writeInt(97);
                raf.write("王五".getBytes());
                raf.writeInt(97);
                raf.close();
        }
}
 | 
 |