Skip to content

Instantly share code, notes, and snippets.

Created January 10, 2012 14:55
Show Gist options
  • Select an option

  • Save anonymous/1589465 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/1589465 to your computer and use it in GitHub Desktop.
My simple Doc read program
package com.dream.textsplitter.io;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class DocReader {
private String APP_FOLDER=DocReader.class.getProtectionDomain().getCodeSource().getLocation().getPath()+"../";
private String RELATIVE_DOC_PATH="ToSplit/TestDoc1.doc"; //OR TestDoc2.doc
private String FULL_DOC_PATH=APP_FOLDER+RELATIVE_DOC_PATH;
public void readDocFile() {
File docFile = null;
WordExtractor docExtractor = null ;
try {
docFile = new File(FULL_DOC_PATH);
FileInputStream fis=new FileInputStream(docFile.getAbsolutePath());
HWPFDocument doc=new HWPFDocument(fis);
docExtractor = new WordExtractor(doc);
}
catch(Exception exep) {
System.out.println(exep.getMessage());
}
//!!!!!!!! THIS IS WHERE THE ISSUE !!!!!!!!!
System.out.println(docExtractor.getText().length());
}
public static void main(String[] args) {
DocReader reader = new DocReader();
reader.readDocFile();
}
}
This is my test text
This is my test text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment