private void writeDocument( Document document, File file )
        throws TransformerException, FileNotFoundException
    {
        document.normalize();
        DOMSource source = new DOMSource( document );
        StreamResult result = new StreamResult( new FileOutputStream( file ) );
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
        transformer.transform( source, result );
    }
private void writeDocument ( Document document , File file ) throws TransformerException , FileNotFoundException { document . normalize ( ) ; DOMSource source = new DOMSource ( document ) ; StreamResult result = new StreamResult ( new FileOutputStream ( file ) ) ; Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; transformer . transform ( source , result ) ; }
write document to the file

@param document
@param file
@throws TransformerException
@throws FileNotFoundException