Code example for FileChannel

Methods: readsize

0
    } 
 
    public static byte[] getFileAsBytes(String file) throws Exception{
        FileInputStream fis = new FileInputStream(file);
        FileChannel fc = fis.getChannel();
        byte[] data = new byte[new Long(fc.size()).intValue()];
        ByteBuffer bb = ByteBuffer.wrap(data);
        fc.read(bb);
        System.out.println(data.length);
        return data;
    } 
 
} 
Contextual code suggestions in your IDE  Get Codota for Java