Hi i am trying to read text from doc and docx file, for doc files i am doing this
package test;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class ReadFile {
public static void main(String[] args) {
File file = null;
WordExtractor extractor = null;
try {
file = new File("C:\\Users\\rijo\\Downloads\\r.doc");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
HWPFDocument document = new HWPFDocument(fis);
extractor = new WordExtractor(document);
String fileData = extractor.getText();
System.out.println(fileData);
} catch (Exception exep) {
}
}
}
But this gives me an org/apache/poi/OldFileFormatException exception.
Any idea how to fix this?
Also I need to read Docx and PDF files ? any good way to read all type of files?