OnJava8-Examples/io/LargeMappedFiles.java

21 lines
643 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: io/LargeMappedFiles.java
// Creating a very large file using mapping.
import java.nio.*;
import java.nio.channels.*;
import java.io.*;
import static net.mindview.util.Print.*;
public class LargeMappedFiles {
static int length = 0x8000000; // 128 MB
2015-04-20 15:36:01 -07:00
public static void main(String[] args) throws Exception {
MappedByteBuffer out =
new RandomAccessFile("test.dat", "rw").getChannel()
.map(FileChannel.MapMode.READ_WRITE, 0, length);
for(int i = 0; i < length; i++)
out.put((byte)'x');
print("Finished writing");
for(int i = length/2; i < length/2 + 6; i++)
printnb((char)out.get(i));
}
2015-05-05 11:20:13 -07:00
} ///:~