• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading RTF File in Java

 
Lalavis Viswanath
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I want to read an RTF file & convert into a text format.
When I read an RTF file it comes along with binary notation.
I used RTFEditorKit.But it is not reading from the file.
The code is given below.
RTFEditorKit kit = new RTFEditorKit();
String filePath = "d:/test/111.rtf";
FileReader reader = new FileReader(filePath);
Document doc = kit.createDefaultDocument();
kit.read(reader,doc,0);
int len = doc.getLength();
String str = doc.getText(0,len);
System.out.println("Length " + len + "str " + str);

OUTPUT
------
Length 0str
I think it is not reading.
Is it a problem in jdk itself or Iam wrong.
This is very urgent.
Let me know if there are any other options available
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried out your code on a default RTF file. First I got a NullPointerException because of something to do with a StyleDefiningDestination class. So I went back and applied the bold style to the text... then everything got read in OK...

Not sure why you are able to read the file but not get the length or text in it...

I know that RTFEditorKit has this and many other problems too... you might have to extend RTFEditorKit yourself to make it work properly...
[ March 20, 2003: Message edited by: Nathan Pruett ]
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that RTFEditorKit has this and many other problems too... you might have to extend RTFEditorKit yourself to make it work properly...

Is it?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!