Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

RTF parsing with RTFEditorKit

843806Aug 30 2007 — edited Aug 30 2007
Hi,

I've got a problem while parsing RTF file with RTFEditorKit. It throws an exception saying "Too many close-groups in RTF text". I've tried to open the document in MS Word and it worked just fine.

I guess that the document is malformed somehow, but MS Word just ignores the case while RTFEditorKit fails. Is there any solution about this issue? I've googled a bit but there's nothing useful on the subject.

Here is my code
RTFEditorKit rtf = new RTFEditorKit();
FileInputStream fi = new FileInputStream("test.rtf");
Document doc = rtf.createDefaultDocument();
rtf.read(fi, doc, 0);
String plainText = new String(doc.getText(0, doc.getLength()).getBytes("ISO-8859-1"), "cp1251");
System.out.println(plainText);
Maybe there is other open source API for RTF parsing? All I need - is just extract plain text data from RTF.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2007
Added on Aug 30 2007
1 comment
1,154 views