Use the HTMLEditorKit.write()
method.
Save HTMLDocument
-
03-06-2022 - |
Question
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.
La solution
Autres conseils
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());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow