Code example for RandomAccessFile

Methods: closegetFDwrite

0
    Random random = new Random();
    byte[] data = new byte[size];
    random.nextBytes(data);
 
    newFile.createNewFile();
    RandomAccessFile file = new RandomAccessFile(newFile, "rws");
 
    file.write(data);
       
    file.getFD().sync();
    file.close();
  } 
 
  /** 
   * Verify that du returns expected used space for a file. 
   * We assume here that if a file system crates a file of size  
   * that is a multiple of the block size in this file system, 
   * then the used size for the file will be exactly that size. 
   * This is true for most file systems. 
   *  
   * @throws IOException