
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 0.47 KB | hits: 20 | expires: Never
How can I use ReadableByteChannel to get file contents and store it in byteBuffer?
File file = new File(fileName);
try {
ReadableByteChannel channel = new FileInputStream(fileName).getChannel();
ByteBuffer buf = ByteBuffer.allocateDirect(file.length());
// How can use buf.read to get all the contents?
} catch (Exception e){
}
FileChannel channel = new FileInputStream(fileName).getChannel();
ByteBuffer buf = channel.map(MapMode.READ_ONLY,0,channel.size());