import java.io.File; 
import java.io.IOException; 
import java.io.RandomAccessFile; 
import java.nio.MappedByteBuffer; 
import java.nio.channels.FileChannel; 

public class JI9053473 {

	//Path to the generated file 
	private static final String path = "D:\\tmp\\"; 
	private static final String fileName = "myMem"; 

	public static void main(String[] args){ 

		File myFile = new File(path+fileName+"_"+System.currentTimeMillis()+".txt"); 

		if(myFile.exists()){ 
			myFile.delete(); 
			System.out.println("Delete old file."); 
		} 

		try { 
			// Create a RAF 
			RandomAccessFile raf = new RandomAccessFile(myFile, "rw"); 

			// Allocate 524288 byte on the disc 
			MappedByteBuffer buf = raf.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 524288); 

			//Fill with 'a' 
			while (buf.remaining()>=1){ 
				buf.put((byte) 'a'); 
			} 
			buf.force(); 

			// Allocate additional 524288 byte on the disc, at the pointer position 
			// expect: 1048576 byte allocated on the disc 
			// result for 1.8.0_172: 1048576 byte allocated 
			// result for 10.0.1: 524288 byte allocated 
			buf = raf.getChannel().map(FileChannel.MapMode.READ_WRITE, raf.getFilePointer(), 524288); 

			//Fill the 524288 byte with 'b' 
			while (buf.remaining()>=1){ 
				buf.put((byte) 'b'); 
			} 
			buf.force(); 

			//Close the RAF 
			raf.close(); 
		} catch (IOException e) { 
			e.printStackTrace(); 
		} 
	}

}
