AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-file-handling: How to read DOC file in java?

Write a java program which can read the microsoft doc file content.

java x 211
file-handling x 9
Posted On : 2016-02-23 23:54:09.0
profile Rishi Kumar - anyforum.in Rishi Kumar
523188250042
up-rate
4
down-rate

Answers


You can use apache poi library to rad the DOC file content. See the following code snippet to read DOC file using apache poi´s library:

DocReader.java:
-------------------------------------------------
package in.anyforum;

import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;

public class DocReader
{
public static void main(String[] args)
{
File file = null;
WordExtractor extractor = null;
try
{

file = new File("File.doc");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
HWPFDocument document = new HWPFDocument(fis);
extractor = new WordExtractor(document);
String[] fileData = extractor.getParagraphText();
for (int i = 0; i < fileData.length; i++)
{
if (fileData[i] != null)
System.out.println(fileData[i]);
}
}
catch (Exception exep)
{
exep.printStackTrace();
}
}
}


Click Here to download Apache POI Jar

Posted On : 2016-02-24 00:03:51
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129560202
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in