Results 1 to 1 of 1
- 07-18-2009, 08:21 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 18
- Rep Power
- 0
Reading Microsoft Word Document in JAVA
Hi friends,
im using follwing code to read word document in java using apache poi package..
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.extractor.*;
import java.io.*;
public class readDoc
{
public static void main( String[] args )
{
String filesname = "Hello.doc";
POIFSFileSystem fs = null;
try
{
fs = new POIFSFileSystem(new FileInputStream(filesname;
//Couldn't close the braces at the end as my site did not allow it to close
HWPFDocument doc = new HWPFDocument(fs);
WordExtractor we = new WordExtractor(doc);
String[] paragraphs = we.getParagraphText();
System.out.println( "Word Document has " + paragraphs.length + " paragraphs" );
for( int i=0; i<paragraphs .length; i++ ) {
paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n","");
System.out.println( "Length:"+paragraphs[ i ].length());
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}
but im getting exception that
java.io.IOException: Unable to read entire header; -1 bytes read; expected 512 bytes
at org.apache.poi.poifs.storage.HeaderBlockReader.<in it>(HeaderBlockReader.java:78)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<i nit>(POIFSFileSystem.java:83)
how to solve this issue.. please suggest me .. its urgent..
Similar Threads
-
Reading Writing to Microsoft Word -Urgent
By Robert_85 in forum Advanced JavaReplies: 5Last Post: 04-13-2009, 12:20 PM -
copying contents from word document to JTextPane
By success21061985 in forum Advanced JavaReplies: 1Last Post: 11-05-2008, 06:09 AM -
Saving word document from iframe
By anil@netedgecomputing.com in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 05-15-2008, 11:49 AM -
How to make online jsp forms from Microsoft word forms in java
By jiten.mistry in forum Advanced JavaReplies: 2Last Post: 04-28-2008, 10:56 AM -
Java Microsoft VM vs JRE SUN
By Ed in forum New To JavaReplies: 2Last Post: 07-02-2007, 02:09 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks