RTF to Plain Text in Java

前端 未结 4 1088
南方客
南方客 2020-11-30 15:07

How do you convert an RTF string to plain text in Java? The obvious answer is to use Swing\'s RTFEditorKit, and that seems to be the common answer around the Internet. How

4条回答
  •  时光取名叫无心
    2020-11-30 15:31

    You might consider RTF Parser Kit as a lightweight alternative to the Swing RTFEditorKit. The line below shows plain text extraction from an RTF file. The RTF file is read from the input stream, the extracted text is written to the output stream.

    new StreamTextConverter().convert(new RtfStreamSource(inputStream), outputStream, "UTF-8");
    

    (full disclosure: I'm the author of RTF Parser Kit)

提交回复
热议问题