[Java]
Package Java. se. lucene;
Import java. io. FileInputStream;
Import java. io. FileNotFoundException;
Import java. io. IOException;
Import org. apache. poi. hwpf. HWPFDocument;
Import org. apache. poi. hwpf. usermodel. Paragraph;
Import org. apache. poi. hwpf. usermodel. Range;
Public class WordToTxt {
// Create a string buffer
/*
* Cannot be written as StringBuffer stringBuffer = null;
* Otherwise, a null pointer exception is reported.
*/
StringBuffer stringBuffer = new StringBuffer ();
// Convert word
Public String readWord ()
{
// Word document path
String pathword = "F: \ lucene \ doc \ 1.doc ";
Try {
// Create an object for storing Word documents
HWPFDocument doc = new HWPFDocument (new FileInputStream (pathword ));
// Used to obtain the Word Document Content
Range range = doc. getRange ();
// Document paragraph count
Int paragraphCount = range. numParagraphs ();
// Traverse the section to read data
For (int I = 0; I <paragraphCount; I ++)
{
Paragraph pph = range. getParagraph (I );
StringBuffer. append (pph. text ());
System. out. println (stringBuffer. toString ());
}
} Catch (FileNotFoundException e ){
E. printStackTrace ();
} Catch (IOException e ){
E. printStackTrace ();
}
Return stringBuffer. toString (). trim ();
}
Public static void main (String [] args ){
New WordToTxt (). readWord ();
}
}