title: JAVA using RandomAccessFile after seek is very slow. What is the reason?
body: <p>This is my test code</p>
  
  <pre><code>long fileSize = 1024 * 1024 * 512L;
  byte[] bts = new byte[8];
  
  RandomAccessFile randomAccessFile = new RandomAccessFile("f:/test.data", "rw");
  randomAccessFile.setLength(fileSize);
  
  randomAccessFile.seek(0);
  long time = System.nanoTime();
  randomAccessFile.write(bts);
  System.out.println("write1 use:" + (System.nanoTime() - time));
  
  randomAccessFile.seek(1024 * 1024 * 256L);
  time = System.nanoTime();
  randomAccessFile.write(bts);
  System.out.println("write2 use:" + (System.nanoTime() - time));
  </code></pre>
  
  <p>print</p>
  
  <pre><code>write1 use:181051
  write2 use:2029338072
  </code></pre>
  
  <p>It can be seen that writing is 9 bytes twice and the second time is 10000 times slower than the first time.</p>
  
  <p>So I would like to ask why the seek will cause the file to write so slowly. Is there any solution?</p>