import java.nio.file.*;
import java.nio.channels.FileChannel;
import java.io.IOException;
import java.nio.ByteBuffer;
public class RandomFileRead {
public static void main(String[] args) {
Path file = Paths.get(System.getProperty("user.home")).resolve("Beginning Java Struff").resolve("primes.bin");
if(!Files.exists(file)) {
System.out.println(file + " does not exist. Terminating program.");
System.exit(1);
}
final int PRIMESREQUIRED = 10;
final int LONG_BYTES = 8; // Number of bytes for type long
ByteBuffer buf = ByteBuffer.allocate(LONG_BYTES*PRIMESREQUIRED);
long[] primes = new long[PRIMESREQUIRED];
int index = 0; // Position for a prime in the file
try (FileChannel inCh = (FileChannel)(Files.newByteChannel(file))){