public static void convert(String kfDescPath, String textFilePath)
            throws IOException, ParserConfigurationException, SAXException {

        // Get the file descriptor from the XML file.
        KFileDescriptor kfd = new KFileDescriptor(kfDescPath);

        // Validate that keyed file and output text file are not the same.
        String keyedFilename = new File(kfd.getFileName()).getCanonicalPath();
        String textFilename = new File(textFilePath).getCanonicalPath();
        if (keyedFilename.equals(textFilename)) {
            throw new IllegalArgumentException("Output text file cannot be the same input keyed file");
        }

        // Get record data and make sure is correct.
        int kl = kfd.getKeyLength();
        int rs = kfd.getRecordSize();
        if (kl <= 0 || rs <= 0 || kfd.getFieldCount() <= 0) {
            throw new IllegalArgumentException("Invalid input data");
        }

        // Create appropriate file handlers.
        RandomAccessFile file = new RandomAccessFile(keyedFilename, "r");
        BufferedWriter bw = new BufferedWriter(new FileWriter(textFilename));

        // Write the header to the text file.
        writeHeader(kfd, bw);

        // Setup the null key, so valid records can be identified.
        byte[] nullKey = new byte[kl];
        byte[] readKey = new byte[kl]; // record key
        byte[] record = new byte[rs];  // record contents

        // Start cycling through the file.
        long len = file.length();
        long i = 516;
        long reg = 0;
        while (i < len) {
            while (reg < 512 && reg + rs <= len) {
                // Read the key of the current record.
                file.seek(i);
                file.readFully(readKey);
                // If a valid (non null) key is found, read the record and
                // write the text equivalent.
                if (!Arrays.equals(nullKey, readKey)) {
                    file.seek(i);
                    file.readFully(record);
                    writeToText(kfd, record, bw);
                }
                // Reposition the file pointer.
                i += rs;
                reg += rs;
                if (reg + rs > 512) {
                    i += 512 - reg;
                    reg = 512;
                }
            }
            reg = 0;
        }
        // Close everything.
        bw.flush();
        bw.close();
        file.close();
    }