public boolean save(String filename) throws Exception {
        if (null == filename) {
            throw new Exception("Filename must not be null");
        }
        //open the streams and send the height data to the file.
        FileOutputStream fos = null;
        DataOutputStream dos = null;
        try {
            fos = new FileOutputStream(filename);
            dos = new DataOutputStream(fos);
            
            for (int i = 0; i < size; i++) {
                for (int j = 0; j < size; j++) {
                    dos.write((int) heightData[j + (i * size)]);
                }
            }

            fos.close();
            dos.close();
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Error opening file {0}", filename);
            return false;
        } catch (IOException e) {
            logger.log(Level.WARNING, "Error writing to file {0}", filename);
            return false;
        } finally {
            if (fos != null) {
                fos.close();
            }
            if (dos != null) {
                dos.close();
            }
        }

        logger.log(Level.FINE, "Saved terrain to {0}", filename);
        return true;
    }
<code>save</code> will save the heightmap data into a new RAW file
denoted by the supplied filename.

@param filename
           the file name to save the current data as.
@return true if the save was successful, false otherwise.
@throws Exception
            if filename is null.
jme3-terrain/src/main/java/com/jme3/terrain/heightmap/AbstractHeightMap.java