Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Read-entire-file/Java/read-entire-file-2.java
Normal file
20
Task/Read-entire-file/Java/read-entire-file-2.java
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import java.nio.channels.FileChannel.MapMode;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
|
||||
public class MMapReadFile {
|
||||
public static void main(String[] args) throws IOException {
|
||||
MappedByteBuffer buff = getBufferFor(new File(args[0]));
|
||||
String results = new String(buff.asCharBuffer());
|
||||
}
|
||||
|
||||
public static MappedByteBuffer getBufferFor(File f) throws IOException {
|
||||
RandomAccessFile file = new RandomAccessFile(f, "r");
|
||||
|
||||
MappedByteBuffer buffer = file.getChannel().map(MapMode.READ_ONLY, 0, f.length());
|
||||
file.close();
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue