long length=0xffffff; String file = "G:\\a.dat"; MappedByteBuffer out = new RandomAccessFile(file, "r") .getChannel().map(FileChannel.MapMode.READ_ONLY, 0, length); for (int i = 0; i < length; i++) out.put((byte) 'x'); System.out.println("Finished writing"); for (int i = 0; i < 10; i++) System.out.println((char) out.get(i)); // read file
MappedByteBuffer out = new RandomAccessFile(file, "r") .getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);
public class LargeFile { public static void main(String[] args) throws Exception ...{ long length = 0x8ffffff; MappedByteBuffer out = new RandomAccessFile("G:\a.dat", "rw").getChannel() .map(FileChannel.MapMode.READ_WRITE, 0, length); for (int i = 0; i < length; i++) out.put((byte) 'x'); System.out.println("Finished writing"); for (int i = 0; i < 10; i++) System.out.println((char) out.get(i)); // read file } }
String file = "G:\\a.dat";
MappedByteBuffer out = new RandomAccessFile(file, "r")
.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, length);
for (int i = 0; i < length; i++)
out.put((byte) 'x');
System.out.println("Finished writing");
for (int i = 0; i < 10; i++)
System.out.println((char) out.get(i)); // read file
.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);
long length = 0x8ffffff;
MappedByteBuffer out = new RandomAccessFile("G:\a.dat", "rw").getChannel()
.map(FileChannel.MapMode.READ_WRITE, 0, length);
for (int i = 0; i < length; i++)
out.put((byte) 'x');
System.out.println("Finished writing");
for (int i = 0; i < 10; i++)
System.out.println((char) out.get(i)); // read file
}
}