get all html as a String from HTMLDocument

前端 未结 2 1987
执念已碎
执念已碎 2021-01-05 03:43

Im coding in Java..

Does anyone know how i can get the content of a javax.swing.text.html.HTMLDocument as a String? This is what i´ve got so far...

         


        
相关标签:
2条回答
  • 2021-01-05 04:25
    StringWriter writer = new StringWriter();
    kit.write(writer, doc, 0, doc.getLength());
    String s = writer.toString();
    
    0 讨论(0)
  • 2021-01-05 04:27

    You don't need the editor and reader at all - just read the input stream. For example, with commons-io IOUtils.toString(inputStream)

    or you can use:

    Content content = document.getContent();
    String str = content.getString(0, content.length() - 1);
    
    0 讨论(0)
提交回复
热议问题