Corey Nelson wrote:

>So I spent a couple days reading the web site and documentation and getting
>all excited and I decided I'm ready to start coding. So I crack my knuckles
>and whip up a quick sample app just to make sure I understand the basics...
>and it doesn't work. :(
>
>------------------------------------
>import javax.swing.*;
>import java.io.*;
>import net.sourceforge.poi.poifs.filesystem.*;
>
>/**
> * Open an OLE CD file and count the entries.
> *
> * @author  Corey Nelson
> *
> * Excuse the sloppy style. :)
> */
>public class DemoApp1 extends JFrame {
>
>       public DemoApp1() {
>               // Get user to choose a file
>               JFileChooser fileChooser = new JFileChooser();
>               int retVal = fileChooser.showOpenDialog(this);
>               if(retVal == JFileChooser.APPROVE_OPTION) {
>                       File file = fileChooser.getSelectedFile();
>                       System.out.println(file);
>
>                       try{
>                               // Get an InputStream and POI Filesystem
>from the file
>                               InputStream in = new FileInputStream(file);
>                               Filesystem fs = new Filesystem();
>
>                               // Count the entries in root
>                               DirectoryEntry root = fs.getRoot();
>                               System.out.println(root.getName() + " " +
>root.getEntryCount());
>                       }
>                       catch(IOException e) {
>                               System.out.println(e);
>                       }
>               }
>       }
>
>       public static void main (String args[]) {
>               DemoApp1 app = new DemoApp1();
>               System.exit(0);
>       }
>
>}
>------------------------------------
>
>Here's some results:
>
>C:\Documents and Settings\CoreyN\My Documents\NotebookTestFiles\5.nbk
>Root Entry 0
>
>C:\Documents and Settings\CoreyN\Book1.xls
>Root Entry 0
>
>C:\Documents and Settings\CoreyN\My Documents\todo.txt
>Root Entry 0
>
>------------------------------------
>
>I'm sure I'm just doing something dumb or misunderstanding some fundamental
>concept here. Shouldn't I be able to open and read an OLE Compound Document
>this way? Shouldn't the Root have some entries? Shouldn't opening a none OLE
>CD produce some sort or exception?
>
>I'd appreciate it if someone could clue me in. Thanks.
>
>Corey
>
>
>
>
>
Try "FileSystem fs = new FileSystem(in);"

Your code, as written, is opening the file, then ignoring the file and 
creating a brand new POIFS file system and reading its root entry. Being 
a brand new file system, it has no files in its root ...

Marc


Reply via email to