Sunday, June 30, 2013

Word to Text Converter

The WordToTextConverter can be used to convert from a microsoft word 2007+ file to a text file. Again, this program uses the Apache POI library or tika library to extract text from Microsoft Word 2007+ file.

Word file to text converter

import java.util.Iterator;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

public class WordToTextConverter{
public static void main(String[] args){
}catch(ArrayIndexOutOfBoundsException aiobe){
System.out.println("Usage:java WordToTextConverter <word_file> <text_file>");



public static void convertWordToText(String src, String desc){
//create file inputstream object to read data from file
FileInputStream fs=new FileInputStream(src);
//create document object to wrap the file inputstream object
XWPFDocument docx=new XWPFDocument(fs);
//create text extractor object to extract text from the document
XWPFWordExtractor extractor=new XWPFWordExtractor(docx);
//create file writer object to write text to the output file
FileWriter fw=new FileWriter(desc);
//write text to the output file
//clear data from memory
//close inputstream and file writer

}catch(IOException e){e.printStackTrace();}

In the code of the program above,  XWPFDocument is used to construct a Microsoft Word document object from the FileInputStream object. FileInputStream object contains all data of the original Microsoft Word file. To extract all text from the document, you need to use the  XWPFWordExtractor class. You will pass the document object to the constructor of the XWPFWordExtractor when you create an object of the XWPFWordExtractor class. From the XWPFWordExtractor object, you can get the text content of this object by using its getText method. Once you have the text, the FileWriter class can be used to output it to the destination file.

compass app flashLight app


  1. Truly amazing blog. A debt of gratitude is in order for sharing this instructive blog.I have perused every one of the articles in your blog; was truly inspired in the wake of understanding it. Great to discover some new information from this blog. Much obliged for sharing such commendable article through see here.

  2. I am trying the same code on Android Studio but getting library errors.Would you please tell me the versions of Apache POI library used by you?

  3. Thanks your shared!... I hope you will continue to have similar posts to share with everyone! I believe a lot of people will be surprised to read this article! Custom Essay Writing Service

  4. Thanks your shared!... I hope you will continue to have similar posts to share with everyone! I believe a lot of people will be surprised to read this article! Write My Essays

  5. Wow, the effects are wonderful! This is so interesting to look at the changes that could be made to the photo in the process of manipulation. You don't need to miss the opportunity and to use college essay writing services to buy the Photoshop CC software. I will also download it soon.

  6. Is your resume getting results? Are you struggling to get your foot in the door? our service will help you.

  7. In spite of all that I not fathom what the maker is attempting to show up. In any case, here is no mean to share this kind of page and moreover the empty page. Look for this is extraordinary after us and may be this is basically abuse of our chance yet at any rate next time you should take mind next time.