Read doc file in java using poi

package com.howto;

import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.hwpf.HWPFDocument;

/*
 * Here we will learn how to read a Doc file
 */
public class ReadDocFile {

	public static void main(String args[]) throws IOException {
		/*
		 * Create input stream of the doc file - Provide exact path of the doc
		 * file to read
		 */
		FileInputStream fistream = new FileInputStream(
				"File_Path");
		HWPFDocument document = new HWPFDocument(fistream);

		System.out.println("Length of docment is :"
				+ document.characterLength());

		System.out.println(document.getText());

		System.out.println(document.getDocumentText());

	}

}

 

Here we will use POI open source project to read windows doc file. PoI Jar will be required that can be downloaded from apache website.

0 Comments Read doc file in java using poi

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.