Pregunta

package htmldocsave;

import java.io.IOException;

import javax.swing.text.BadLocationException;
import javax.swing.text.html.*;

import java.io.*;

public class HTMLDocSave 
{
    public static void main(String[] args)
    {
        HTMLDocument doc = new HTMLDocument();
        HTMLEditorKit kit = new HTMLEditorKit();

        File f = new File("greeting.html");

        try 
        {
            kit.insertHTML(doc,doc.getLength(),"<b>Hello</b>",0,0,null);
            FileOutputStream fos = new FileOutputStream(f);

            ???????????????????????????
                    fos.close();
        } 
        catch (BadLocationException | IOException e) 
        {
            e.printStackTrace();
        }

    }
}

How to save a HTML document on the file system? The javax.swing.text.html.HTMLDocument class doesn't override the toString() method and getText() removes tags.

¿Fue útil?

Solución

Use the HTMLEditorKit.write() method.

Otros consejos

I guess this post is very similar to your question:Get String from HTMLDocument

Then write the String to a File. There are many different methods to do this. Take a look at Write String to File.

That's all what I exactly needed: kit.write(fos, doc, 0, doc.getLength());

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top