File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Java Products and Servers and the fly likes i want to read an ODT file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "i want to read an ODT file " Watch "i want to read an ODT file " New topic

i want to read an ODT file

Ashok Nettem

Joined: Nov 04, 2007
Posts: 10
i have created the file using Openoffice .org .When i read the file Its giving the junk value.Are there any api to read the content of the file that has extension of .ODT
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

An .odt file is not a plain text file, so if you try to read it as if it is plain text, then you'll get "junk".

I have not used it myself, but there is a Java API for OpenOffice. Have a look at this:

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
jodconverter is a nice library that uses OO to covert between file formats. Since OO understands ODF (of which ODT is part) it might help.

If you want a more direct approach, ODF (and ODT) files are XML files in a zip archive. So you can use the package to open the file, and then process its constituent files using the JAXP API. The file that has the actual content is called "content.xml".
Pat Farrell

Joined: Aug 11, 2007
Posts: 4659

while its true that they are just zip'd XML files, one quick look at the structure of the XML is enough to make one run away and hide.

Thar be dragons....
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
I found the ODF format rather straightforward to deal with. More for the learning effect than for the practical use I wrote an ODS->XLS converter and ODT->PDF/RTF/HTML converter a while ago.

The trickiest part was to reconcile the various styles that get applied, because there are default styles, document default styles, paragraph styles, local styles, etc., and you need to make sure which one gets applied to a particular piece of data.

Processing the actual text or cell contents was comparatively easy.
I agree. Here's the link:
subject: i want to read an ODT file
It's not a secret anymore!