The moose likes Other Open Source Projects and the fly likes File Convertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "File Convertion" Watch "File Convertion" New topic

File Convertion

Shaik Vali

Joined: Feb 07, 2008
Posts: 22
Hi Good Morning everybody

I would like to convert .rtf file to .txt file by java code , please give the solution

Subha Garg
Ranch Hand

Joined: Feb 28, 2008
Posts: 39
java-code-converting-RTF-to-text - a sample code discussed about converting a RTF document to Text output.

RTF to Text conversion using Java swing packages.

This is an example about how to read a RTF document
and printing out all the texts of this RTF file,
as plain text.

I have used packages like javax.swing.text,
javax.swing.text.rtf from Java API.
* This code is provided "AS IS", without warranty of any kind.
* This is a sample code, might be not completely error free.
* This site or author of this code doesn't take any responsibility
* what so ever resulting out of usage of this code.

public class RTF2Text
public RTF2Text(String fileName)
//Reading the RTF file as data input stream
FileInputStream fin = new FileInputStream(fileName);
DataInputStream din = new DataInputStream(fin);

//creating a default blank styled document
DefaultStyledDocument styledDoc = new DefaultStyledDocument();

//Creating a RTF Editor kit
RTFEditorKit rtfKit = new RTFEditorKit();

//Populating the contents in the blank styled document,styledDoc,0);

// Getting the root document
Document doc = styledDoc.getDefaultRootElement().getDocument();

//Printing out the contents of the RTF document as plain text

}catch(Exception ex){
public static void main(String args[])
new RTF2Text(args[0]);


Now this example requires a RTF document, and by compiling this example, and running with a command like:

java RTF2Java myrtffile.rtf

Output will be printed out on screen.
I agree. Here's the link:
subject: File Convertion
It's not a secret anymore!