473,394 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to read word file using java

83
How to read the .doc file into the printable format(ie without ascii code).

It's urgent pls anyone help me


Thanks
Sang
Sep 19 '06 #1
5 42047
.doc files are part binary, part text files. The easiest way to "read" in a microsoft document is by using the OpenOffice api's (http://www.openoffice.org) if you want a formattable/printable document or if you want just the raw bytes then use a ByteArrayInputStream. The OpenOffice api's are _not_ the easiest things to use, but it is a whole lot better than trying to parse through all the crap yourself.

How to read the .doc file into the printable format(ie without ascii code).

It's urgent pls anyone help me


Thanks
Sang
Sep 19 '06 #2
sang
83
Thank you for your replay,

But i am not able to understand your answer please give the java code.
Once again thanks for your replay,
I am waiting for your answer.

Thanks,
Sang.
Sep 20 '06 #3
r035198x
13,262 8TB
Thank you for your replay,

But i am not able to understand your answer please give the java code.
Once again thanks for your replay,
I am waiting for your answer.

Thanks,
Sang.
What he/she meant is that it's easier to use a third party package to read the .doc files. If you do not have one that reads .doc files then you visit the site he has given or google POI.
Sep 20 '06 #4
sang
83
The below code is used to read the document file. But at output it will give the special characters and ascii values. So i want only the readable characters (ie a-z and 0-9) how is possible pls give the solution.

Example code:

import java.io.*;
class fileinput
{
public static void main(String[] args) throws IOException
{
FileInputStream Fin=new FileInputStream("file.doc");
int j;
while((j=Fin.read())!=-1)
System.out.print((char)j);
}
}

Thanks
Sang.
Sep 20 '06 #5
Hi friend,
I have used Jakarta POI library to read the doc file.
This program simply reads the doc file and prints each line on the console, I think this program will help you to read the doc file.

--------------------------------------------------------------------------------
import java.io.File;
import java.io.FileInputStream;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;

public class DocReader {

public void readDocFile() {
File docFile = null;
WordExtractor docExtractor = null ;
WordExtractor exprExtractor = null ;
try {
docFile = new File("c:\\Resume.doc");
//A FileInputStream obtains input bytes from a file.
FileInputStream fis=new FileInputStream(docFile.getAbsolutePath());

//A HWPFDocument used to read document file from FileInputStream
HWPFDocument doc=new HWPFDocument(fis);

docExtractor = new WordExtractor(doc);
}
catch(Exception exep)
{
System.out.println(exep.getMessage());
}

//This Array stores each line from the document file.
String [] docArray = docExtractor.getParagraphText();

for(int i=0;i<docArray.length;i++)
{
if(docArray[i] != null)
System.out.println("Line "+ i +" : " + docArray[i]);
}
}

public static void main(String[] args) {
DocReader reader = new DocReader();
reader.readDocFile();
}
}
-------------------------------------------------------------------------------------
Mar 14 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: asenthil | last post by:
Hai, i'm a beginner to java... just now i had tried to read and write files using java... and then i had tried to connect a database using jdbc... now i want to export the data's from a...
1
by: datttanand | last post by:
hello everybody, How to read a MS Word File using javascript? I want to read some data from existing file and wants to append it to my new word file, can anybody tell me how to do tjis with...
1
by: =?Utf-8?B?c3Vpcw==?= | last post by:
Hi every body, i have a problem with how to read .MSG file (Outlook) using vb.net ? using this articles the author has already explain how to read .MSG file using stuctured storage (vc++) ...
4
by: Alexander Vasilevsky | last post by:
Need to read Word file without Office installation. It's possible? http://www.alvas.net - Audio tools for C# and VB.Net developers
2
by: yaveus | last post by:
Hi?I am studying java on my own and got stack on how to read and post data to a file using java e.g how will you solve this: A simple application that, when run, Welcomes the users and tells them...
1
by: SagarDoke | last post by:
I have a txt file. I want to add the data from that file into the excel file using java. That data is delimited by spaces as follows: 1 Sagar Doke Address Roll No. City 2 ABC ...
7
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, I am using visual studio C# window and I have an xml file which I need to read that file using Object Oriented program. What codes I should use in my class to load and read that xml file....
2
by: arivusudar.nc | last post by:
I have to open word document in web page using php coding in linux server.. already i worte in windows supporting php code. but it is not working in my linux server so, i need how to open word...
3
by: leninbecse | last post by:
How to Write the Read-only file in java?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.