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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
import java.io.*;
import org.apache.poi.poifs.eventfilesystem.*;
import org.apache.poi.hdf.extractor.*;
public class PoiTest {
public static void main(String[] args)
throws IOException {
final String filename = args[0];
POIFSReader r = new POIFSReader();
r.read(new FileInputStream(filename));
// create temp file of content
String tempF="test.txtl";
//
testDoc td=new testDoc(filename, tempF);
td.getText();
}
} // end of class PoiTes
class testDoc {
String origFileName;
String tempFile;
WordDocument wd;
testDoc(String origFileName, String tempFile) {
this.tempFile=tempFile;
this.origFileName=origFileName;
}
public void getText() {
try {
wd = new WordDocument(origFileName);
Writer out = new BufferedWriter(new FileWriter(tempFile));
wd.writeAllText(out);
out.flush();
out.close();
}
catch (Exception eN) {
System.out.println("Error reading document:"+origFileName+"\n"+eN.toString());
}
} // end for getText
} // end of class |
Partager