Java 中 RTF 到纯文本
在 Java 中如何将 RTF 字符串转换为纯文本?显而易见的答案是使用 Swing 的 RTFEditorKit,这似乎是 Internet 上的常见答案。然而,声称返回纯文本的 write 方法实际上并未实现......它是硬编码的,只是在 Java6 中抛出 IOException 。
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. However the write method that claims to return plain text isn't actually implemented... it's hard-coded to just throw an IOException in Java6.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在 Java 6 中使用 Swing 的 RTFEditorKit,如下所示:
并且可以正常工作。
I use Swing's RTFEditorKit in Java 6 like this:
and thats working.
尝试 Apache Tika: http://tika.apache.org/0.9/formats.html#Rich_Text_Format
Try Apache Tika: http://tika.apache.org/0.9/formats.html#Rich_Text_Format
您可能会考虑将 RTF Parser Kit 作为 Swing RTFEditorKit 的轻量级替代品。下面的行显示了从 RTF 文件中提取的纯文本。从输入流读取 RTF 文件,将提取的文本写入输出流。
(全面披露:我是 RTF Parser Kit 的作者)
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.
(full disclosure: I'm the author of RTF Parser Kit)
这里是解析和解析的完整代码将 RTF 写入纯文本
Here is the full code to parse & write RTF as a plain text