| 10 | public class LargeMappedFiles { |
| 11 | static int length = 0x8000000; // 128 MB |
| 12 | public static void |
| 13 | main(String[] args) throws Exception { |
| 14 | try( |
| 15 | RandomAccessFile tdat = |
| 16 | new RandomAccessFile("test.dat", "rw") |
| 17 | ) { |
| 18 | MappedByteBuffer out = tdat.getChannel().map( |
| 19 | FileChannel.MapMode.READ_WRITE, 0, length); |
| 20 | for(int i = 0; i < length; i++) |
| 21 | out.put((byte)'x'); |
| 22 | System.out.println("Finished writing"); |
| 23 | for(int i = length/2; i < length/2 + 6; i++) |
| 24 | System.out.print((char)out.get(i)); |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | /* Output: |
| 29 | Finished writing |