Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners 16686-How-to-read-the-.doc How to read the .doc/ .docx file in Java Program

Have Programming Question? Ask it here!
 
 
 


Nadeem Kumar
How to read the .doc/ .docx file in Java Program
2 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


Hi,

I am beginner in Java programming language. Can anybody explain How to read .doc file in Java language. Please provide any online reference so that i try it.

Regards,


Advertisement
View Answers

February 25, 2011 at 11:08 AM


Hi,

In java programming language we normally using the POI Library to read the word document file. For doing this we will make class HWPFDocument which throw all of the Word file data and the class WordExtractor extract the text from the Word Document. The method getParagraphText() of WordExtractor class get the text from the word file as an array and display the data on word file. This way you can read the .doc or .docx file in Java programming language.

Thanks



August 30, 2012 at 6:52 PM


package doc.reader;

import org.apache.poi.poifs.filesystem.*; import org.apache.poi.hpsf.DocumentSummaryInformation; import org.apache.poi.hwpf.*; import org.apache.poi.hwpf.extractor.*; import org.apache.poi.hwpf.usermodel.HeaderStories;

import java.io.*;

public class ReadDocFileFromJava {

public static void main(String[] args) {
    /**This is the document that you want to read using Java.**/
    String fileName = "d\\Resume.doc";

    /**Method call to read the document (demonstrate some useage of POI)**/
    readMyDocument(fileName);

}
public static void readMyDocument(String fileName){
    POIFSFileSystem fs = null;
    try {
        fs = new POIFSFileSystem(new FileInputStream(fileName));
        HWPFDocument doc = new HWPFDocument(fs);

        /** Read the content **/
        readParagraphs(doc);

        int pageNumber=1;

        /** We will try reading the header for page 1**/
        readHeader(doc, pageNumber);

        /** Let's try reading the footer for page 1**/
        readFooter(doc, pageNumber);

        /** Read the document summary**/
        readDocumentSummary(doc);

    } catch (Exception e) {
        e.printStackTrace();
    }
}   

public static void readParagraphs(HWPFDocument doc) throws Exception{
    WordExtractor we = new WordExtractor(doc);

    /**Get the total number of paragraphs**/
    String[] paragraphs = we.getParagraphText();
    System.out.println("Total Paragraphs: "+paragraphs.length);

    for (int i = 0; i < paragraphs.length; i++) {

        System.out.println("Length of paragraph "+(i +1)+": "+ paragraphs[i].length());
        System.out.println(paragraphs[i].toString());

    }

}

public static void readHeader(HWPFDocument doc, int pageNumber){
    HeaderStories headerStore = new HeaderStories( doc);
    String header = headerStore.getHeader(pageNumber);
    System.out.println("Header Is: "+header);

}

public static void readFooter(HWPFDocument doc, int pageNumber){
    HeaderStories headerStore = new HeaderStories( doc);
    String footer = headerStore.getFooter(pageNumber);
    System.out.println("Footer Is: "+footer);

}

public static void readDocumentSummary(HWPFDocument doc) {
    DocumentSummaryInformation summaryInfo=doc.getDocumentSummaryInformation();
    String category = summaryInfo.getCategory();
    String company = summaryInfo.getCompany();
    int lineCount=summaryInfo.getLineCount();
    int sectionCount=summaryInfo.getSectionCount();
    int slideCount=summaryInfo.getSlideCount();

    System.out.println("---------------------------");
    System.out.println("Category: "+category);
    System.out.println("Company: "+company);
    System.out.println("Line Count: "+lineCount);
    System.out.println("Section Count: "+sectionCount);
    System.out.println("Slide Count: "+slideCount);

}

}



Related Tutorials/Questions & Answers:
How to read the .doc/ .docx file in Java Program
How to read the .doc/ .docx file in Java Program  Hi, I am beginner in Java programming language. Can anybody explain How to read .doc file in Java.... This way you can read the .doc or .docx file in Java programming language. Thanks
read doc and docx file in javascript
read doc and docx file in javascript  How i read doc and docx file in javascript
Advertisements
About search and replace contains of .doc or .docx file using java.
About search and replace contains of .doc or .docx file using java.  Hi , I am trying to replace contents of ms.word document in .doc or .docx... any one tell me how could I replace them using java
serch document from .doc and .docx file
serch document from .doc and .docx file  how to find particular word from .doc and .docx file and that date insert into a data base
I have one small doubt , does this code read Microsoft Office suit file format data such as .doc , .docx etc ?
I have one small doubt , does this code read Microsoft Office suit file format data such as .doc , .docx etc ?  import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class ReadFileExample
How to read a line from a doc file
How to read a line from a doc file  How to read a line from a doc file   Hi Friend, To run the following code, you need to download POI... void main(String[] args) { File file = null; WordExtractor extractor = null
how read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
how to store/retrieve doc file - Java Beginners
how to store/retrieve doc file  i want to wirte a code that stores/ retrieves .doc files to the mysql database using jsp pages... can anyone help me with the code?  Use this stuff inside your jsp page for store file
doc file - Java Beginners
doc file   i want to read .doc file ?....it is a part of my project plz help. if possible , can anyone give me the code
how to convert doc file into html using java swing
how to convert doc file into html using java swing  i want to convert doc file into html and display it on jtextarea please help me and give the sample code
How to Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file...()?. The output of read file line by line in Java is printed on console... of Java API is another way to read a file line by line in Java. It used
Java Read .doc file using POI library
Java Read .doc file using POI library In this section, you will learn how to read the word document file using POI library. The class HWPFDocument throw all of the Word file data and the class WordExtractor extract the text from
How to Read a File in Java
How to Read a File in Java? In this section we are going to know, How to read a file in Java. We have to follow three step to read a File. First get... can be very inefficient. Example Here is the program to read a file in Java
Program to read a dynamic file content - Java Beginners
Program to read a dynamic file content  Hi, In a single... the database. Im using MySql Database and a standalone java program. I...", "020209.txt", "030209.txt","040209.txt". In a single file I'll get the datas
How To Read File In Java with BufferedReader
How To Read File In Java with BufferedReader class - example code This tutorial shows you how you can read file using BufferedReader class in your program... java.io.*; /** * How To Read File In Java with BufferedReader class
How To Read File In Java
How To Read File In Java In this section we will discuss about about how data.... Example This example demonstrates that how to read a file in java. To read a file... a Java Program to read the data of a file and used the FileInputStream class
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
Merge multiple jasper file to one word Doc using java
Merge multiple jasper file to one word Doc using java   how to Merge multiple jasper file to one word Doc using java
How to read properties file in java
How to read properties file in java Description of Example:- In this example...= 8285279608 Example of Read properties file in java import java.io.... read properties file;- ResourceBundle. Properties Class.  
How to read file in java
How to read file in java Java provides IO package to perform reading and writing operations with a file. In this section you will learn how to read a text file line by line  in java. FileInputStream- This class reads bytes from
How to read an eml file? - Java Beginners
How to read an eml file?  Hello dears, now i want to read en eml file stored in a folder. is it possible to use the same code for reading a txt file? or do i have to use javamail api? Thanks Spalax
How to read properties file in Java?
the java.util.Properties class for reading a property file in Java program...Example program of reading a properties file and then printing the data... to value. The java.util.Properties class is used to read the properties file
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line... to read the big file in your java program. For example you have to process some... to read character files easily in Java program. Constructor takes file name
Reading .doc file using swing
Reading .doc file using swing  Sir, Could U Please Tell me the Way To Read .doc file in java using swing,with code
java read file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
Read file in java
Read file in java  Hi, How to Read file in java? Thanks   Hi, Read complete tutorial with example at Read file in java. Thanks
Write data in doc file
Write data in doc file  How to write data or string in word file
How to check if a file is read-only in java
How to check if a file is read-only in java A read-only file is any file... file: Java API provides the functions to find if any file is read only... will not be able to make changes to it. You can make a file read-only by using
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
How to read a large text file line by line in java?
How to read a large text file line by line in java?  I have been assigned a work to read big text file and extract the data and save into database... you kind advice and let's know how to read a large text file line by line in java
How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji... how to write the program
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
Java read binary file
Java read binary file  I want Java read binary file example code... at Reading binary file into byte array in Java. Thanks   Hi, There is many more examples at Java File - Learn how to handle files in Java with Examples
How can i read a file from nth line onwards in java
How can i read a file from nth line onwards in java  Hi, I need to read a file content from its nth line onwards till end. How can i implement it in java. Regards, Chinnu
How to make a file read-only in java
How to make a file read-only in java A read-only file is any file... program will make a the file read only To make file read only file.setReadOnly(); method is used. In the page you learned how to make a file read only
Read File in Java
Read File in Java This tutorial shows you how to read file in Java. Example... shows you how to read file in Java * */ public class ReadFileExample { public... is the complete example of Java program that reads a character file and prints
How to check a file is read-able or not in java
Description: This example demonstrate how to check a file have read permission... check for its read property of a file. As in the file path we see '\'... or false depends on the file have read property at the specified path that is set
Java: Searching a string from doc files
Java: Searching a string from doc files   I want to search a string from DOC, DOCX files in java. Can anyone please help me
how to read this xml file - XML
how to read this xml file  i want to read this xml file using java... read i have tried lot more , but i am not able to read this xml file... name=client menu=client action=read user employee add
convert a file .doc to .zip
convert a file .doc to .zip  hiii, I uploaded a file with extension .doc now i required with .zip   Hi Friend, Try the following code... language="java" %> <HTml> <HEAD><TITLE>Display file upload form
how to create xml schema from xml doc using java
how to create xml schema from xml doc using java  i want to create xml schema from xml document programatically using java... am using Netbeans IDE... need to create the xml schema for that document and send both xml doc ans schema
JDOM example in java, How to read a xml file in java.
JDOM example in java, How to read a xml file in java. In this tutorial, we will see how to  read a xml file in java. Code. Student.xml...;     File file = new File(data
Java - Read file Applet
Java - Read file Applet     ... the concept of the reading file from an applet. This program illustrates you how an applet can read the content from the given file. In this program we passes
Java read file line by line - Java Tutorial
; This program reads the bytes from file and display it to the user. Download...:\nisha>java FileRead this is a file C...C:\nisha>javac ReadFile.java C:\nisha>java
Java read file in memory
Java read file in memory In this section, you will learn how to read a file... and then read the file... for the  file, and then call map( ) to produce a MappedByteBuffer, which
Java read properties file
Java read properties file In this section, you will learn how to read... Video tutorial of reading properties file in Java. Here is the code... can read any properties file. Output: Name: RoseIndia
How to read loops in Java
How to read loops in Java  Example that explains how to read loop in Java
How to Read Excel file Using Java
How to Read Excel file In this section,you will learn how to read excel file... and every cell and stored the excel file values into the vector.This Vector data is then used to display file values on the console. Here is the code
Java Read CSV file
Java Read CSV file In this tutorial, you will learn how to read csv file. CSV (Comma Separated Value) is a common type of data file which can be exported... opened a file data.csv  and created a BufferedReader object to read
Advertisements
 

 

 

DMCA.com