| 12345678910111213141516171819202122232425262728293031 |
Package com. Howto; import java. Io. FileInputStream; import java. Io. IOException; import org. Apache. Poi. HWPF. Hwpfdocument; /** Here we'll learn how to read a Doc file */public class readdocfile { Public static void main(String args[]) Throws IOException { /** Create input stream of the doc file-provide exact path of the doc* file to read */ fileinputstream fistream = new fileinputstream( "File_path"); hwpfdocument document = new hwpfdocument(fistream) ; System. Out. println("Length of Docment is:" + document. Characterlength()); System. Out. println(document. GetText()); System. Out. println(document. Getdocumenttext()); }} |
Here we'll use the POI open source project to read Windows doc file. The PoI Jar would be required the can downloaded from Apache website.
Read doc file in Java using POI