Code given below helps you to solve your problem.
Code:
import org.apache.poi.poifsfilesystem.filesystem .*;
import org.apache.poi.hwpf .*;
import org.apache.poi.hwpf.extractor .*;
import java.io. *;
Public class viewDoc
{ Public static void hand(String[] args)
{
String fname = "slim.hwpfdoc";
POIFSFileSystem fsfilesystem = null;
try{
fsfilesystem = new POIFSFileSystem(new FileInputStream(fname) );
HWPFDocument hwpfdoc = new HWPFDocument(fsfilesystem);
WordExtractor wordextractor = new WordExtractor(hwpfdoc);
String[] str = wordextractor.getParagraphText();
System.out.System.out.println( "Word hwpfdocument has" + Paragraphs.length + "Paragraphs" );
for( int i =0; I <str.length; I + + ) {
str[i] = Paragraph[i].replaceAll("\cM? r? n","");
System.out.System.out.println( "Length"+ str[ i ].length());
}}
catch(Exception e) {
e.printStackTrace();
} } }
Bookmarks