dcsimg

How can I save the content of JTextPane as an html file?

Sandip Chitale

Say the content type of the JTextPane was of MIME type "text/html" then you can do -

import javax.swing.text.html.*;

...

JTextPane p = new JTextPane();
p.setContentType("text/html");

...

HTMLDocument hd = (HTMLDocument) p.getDocument();
HTMLWriter hw = new HTMLWriter(outputStream, hd);
hd.write();