Code example for FileChannel

Methods: close, map, size

0
	    FileChannel ch = null;
	    byte[] bytes = null;
	    try { 
	        fin = new FileInputStream(f);
	        ch = fin.getChannel();
	        int size = (int) ch.size();
	        MappedByteBuffer buf = ch.map(MapMode.READ_ONLY, 0, size);
	        bytes = new byte[size];
	        buf.get(bytes);
 
	    } catch (IOException e) {
	        // TODO Auto-generated catch block 
	        e.printStackTrace();
	    } finally { 
	        try { 
	            if (fin != null) {
	                fin.close();
	            } 
	            if (ch != null) {
	                ch.close();
	            } 
	        } catch (IOException e) {
	            // TODO Auto-generated catch block 
	            e.printStackTrace();
	        }