Code example for FileChannel

Methods: read, size

0
        byte header[] = new byte[HEADERLEN];
        try { 
            FileInputStream fis;
            fis = new FileInputStream(rom);
            FileChannel fc = fis.getChannel();
            fc.read(ByteBuffer.wrap(header), fc.size() - HEADERLEN);
            fis.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        } 
        return header;
    } 
 
    public WonderSwanHeader(File rom) {
        this(getHeaderFromFile(rom));
    } 
 
    public WonderSwanHeader(byte[] header) {
        if (header == null || header.length != HEADERLEN) {
            throw new IllegalArgumentException("Header must be " + HEADERLEN + " bytes");