epfl-archive/Alpano/tests/ch/epfl/alpano/dem/MemMapExample.java
2022-04-07 18:43:21 +02:00

26 lines
747 B
Java

package ch.epfl.alpano.dem;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.nio.ShortBuffer;
import java.nio.channels.FileChannel.MapMode;
public class MemMapExample {
public static void main(String[] args)
throws IOException {
File f = new File("HGT"+File.separatorChar+"N46E007.hgt");
long l = f.length();
try (FileInputStream s = new FileInputStream(f)) {
ShortBuffer b = s.getChannel()
.map(MapMode.READ_ONLY, 0, l)
.asShortBuffer();
for (int i = 0; i <= 5; ++i)
System.out.println(b.get(i));
System.out.println("-----------------");
for (int i = 12967195; i < 12967201; ++i)
System.out.println(b.get(i));
}
}
}