import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
public class TestRandomAccessFile {
public static void main(String[] args) throws FileNotFoundException {
try{
RandomAccessFile rf = new RandomAccessFile("random.txt","rw");
rf.writeBoolean(true);
rf.writeInt(123456);
rf.writeChar('j');
rf.writeDouble(1234.56);
rf.seek(1); //文件指针跳转到1位置
System.out.println(rf.readInt());
System.out.println(rf.readChar());
System.out.println(rf.readDouble());
rf.seek(0);
System.out.println(rf.readBoolean());
rf.close();
}catch(Exception e){
e.printStackTrace();
}
}
}