title: seek(0) method in RandAccessFile deleting my content
body: <p>In this project, I want to place each new number at the beginning of the random access file. But the seek() method deletes every other number in the file. I don't know why.</p>
  <pre><code>package first;
  
  import java.io.*;
  
  public class Demo {
      public static void main(String[] args) throws IOException, InterruptedException {
  
          File file = new File(&quot;test.dat&quot;);
          RandomAccessFile raf = new RandomAccessFile(file, &quot;rw&quot;);
          raf.setLength(0);
          for (int i = 0; i &lt; 10; i++) {
              raf.writeInt(i);
              raf.seek(0);//setting the pointer to the beginning of the file
          }
  
          //printing the numbers
          System.out.println(raf.length());
          for (int i = 0; i &lt; 10; i++) {
              raf.seek(i * 4);
              System.out.println(raf.readInt());
  
          }
  
      }
  
  }
  
  </code></pre>
  <p>The console output is thus</p>
  <pre><code>Exception in thread &quot;main&quot; java.io.EOFException
      at java.base/java.io.RandomAccessFile.readInt(RandomAccessFile.java:846)
      at liangweb/chapter37.Demo.main(Demo.java:20)
  4
  9
  
  
  </code></pre>