public void update(DbfRecord record) throws IOException {
        if (isReadOnly()) {
            throw new UnsupportedOperationException("Trying to write to a read-only file.");
        }

        // if header was never written, write it first, then output the record
        if (!headerWritten) {
            writeHeader();
        }

        // Check if record has an index
        if (record.getRecordIndex() < 0) {
            throw new IllegalArgumentException("Record index is not set, unable to update record. " +
                    "Set record index or call write() method to add a new record to file.");
        }

        // Check if this record matches record size specified by header and number of columns.
        // Client can pass a record from another DBF that is incompatible with this one and that would corrupt the file.
        if (record.getHeader() != header && (record.getHeader().getColumnCount() != header.getColumnCount()
                                            || record.getHeader().getRecordLength() != header.getRecordLength()))
            throw new IllegalStateException("Record parameter does not have the same size and number of columns as the " +
                                "header specifies. Writing this record would corrupt the DBF file. " +
                                "This is a programming error, have you mixed up DBF file objects?");

        if (dbfFile == null) {
            throw new IllegalStateException("Write stream is null. Either a stream that can not be " +
                                "written to is opened (a read-only stream) or a stream has not been opened at all.");
        }


        // Move to the specified record, note that an exception will be thrown if stream is not seekable!
        // This is ok, since we provide a function to check whether the stream is seekable.
        long nSeekToPosition = (long) header.headerLength() + ((long) record.getRecordIndex() * (long) header.getRecordLength());

        //check whether we can seek to this position. Subtract 1 from file length (there is a terminating character 1A at the end of the file)
        //so if we hit end of file, there are no more records, so return false;
        if (dbfFile.length() < nSeekToPosition) {
            throw new IndexOutOfBoundsException("Invalid record position. Unable to save record.");
        }

        // move to record start
        dbfFile.seek(nSeekToPosition);

        // write
        record.write(dbfFile);
    }