Here you can find the source of write(Writer out, Document doc)
private static void write(Writer out, Document doc) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.Writer; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; public class Main { private static void write(Writer out, Document doc) throws IOException { try {// ww w.ja va 2 s . c o m new DefaultEditorKit().write(out, doc, 0, doc.getLength()); } catch (BadLocationException e) { throw new IOException(e.getMessage()); } } }