For Programmers: Free Programming Magazines  


Home > Archive > Java Help > September 2004 > POI library help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author POI library help
José María Mateos

2004-09-30, 8:59 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi everyone,

I'm trying to parse some .doc files using POIFS but I'm having
some problem. Currently, I have this method in one class:

protected void processDocs()
{
File directorio = new File(path);
String docs[] = directorio.list();
FileInputStream documento = null;
POIFSDocumentPath POIpath = new POIFSDocumentPath(
Config.getDocsPath().split(
File.separator));
System.out.println("Path: " + POIpath.toString());
POIFSReader docReader = new POIFSReader();
WordDocumentReader docProcess = new WordDocumentReader();
System.out.println("Documentos en el path:");
for (int i = 0; i < docs.length; i++) {
System.out.println(docs[i]);
docReader.registerListener(docProcess, POIpath, docs[i]);
try {
documento = new FileInputStream(
directorio.toString() +
File.separator + docs[i]);
docReader.read(documento);
System.out.println("Doc leído");
} catch (Exception e) {
System.out.println("Ha ocurrido un error: " + e.getMessage());
}
}
}

Config.getDocsPath() returns the path where the .doc files are
stored, relative to the root directory (/ in Unix), and "path" var
contains the whole path.

WordDocumentReader is simply:

import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.poifs.eventfilesystem.*;
import java.io.*;
import java.util.*;

public class WordDocumentReader implements POIFSReaderListener
{

public void processPOIFSReaderEvent (POIFSReaderEvent event)
{
DocumentInputStream documento = event.getStream();
System.out.println("Estoy leyendo");
System.out.println(event.getName());
try {
while (documento.available() > 0)
System.out.println((char)documento.read());

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

However, docReader.read(documento) does nothing, does not even
throw an exception or any message... anyone has a clue of what's going
on?

Best regards.
- --
** Las Penas del Agente Smith: http://blogs.eurielec.etsit.upm.es/chema **
http://EuropeSwPatentFree.hispalinux.es - EuropeSwPatentFree
GPG key ID: 0x2948FA19 | Please encrypt private mail
Software Libre Formación - http://www.sl-form.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBXFPA9P6GbSlI+hkRAq6fAJ0ak0rVt4hP
oqbYTktdK2sebOIqAgCgsgj3
0VrrM7xrpjcxenPjgpq+BFE=
=AiGk
-----END PGP SIGNATURE-----
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com