1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
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.