File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Creating a TreeMap form Enumerated Zip Entries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating a TreeMap form Enumerated Zip Entries" Watch "Creating a TreeMap form Enumerated Zip Entries" New topic
Author

Creating a TreeMap form Enumerated Zip Entries

Shawn Franks
Greenhorn

Joined: May 18, 2010
Posts: 23
I am completely Horrid when it comes to HashMaps.

Im looking for someone that can help me or show me the direction of creating i dynamic TreeMap.

What I want to accomplish is reading the content listing of a Zip archive which basically lists every file in string format with the entire directory path.

Thats the easy part.

I need to break down all of those entries and create a TreeMap from them so I can basically create a Structure i can access to display the files in something similar to a file explorer.

Any help would be greatly appreciated. or even other ways to view the contents of a zip file in an explorer type fashion as apposed to all files at once
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

Check out javax.swing.JTree and javax.swing.tree.DefaultTreeModel. You'll find a link to a tutorial in the JTree API.


luck, db
There are no new questions, but there may be new answers.
Shawn Franks
Greenhorn

Joined: May 18, 2010
Posts: 23
Darryl Burke wrote:Check out javax.swing.JTree and javax.swing.tree.DefaultTreeModel. You'll find a link to a tutorial in the JTree API.


Unfortunately I need to do it without swing this is for a customized API so It pretty much needs to be done without any special components. Thank you though. I should have clarified when i asked for other ways so I didnt take your time.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If I understand you correctly, you want a map of maps. Each key ("path element") points to a map containing the same thing.
Shawn Franks
Greenhorn

Joined: May 18, 2010
Posts: 23
Yes that is pretty much correct.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What specifically are you having an issue with?
Shawn Franks
Greenhorn

Joined: May 18, 2010
Posts: 23
I don't understand how I would dynamically create the tree map. Since the zip can have a multiple number of directories and there is no real way to tell it cannot be hard coded. If possibly you could show a little example of what you would do to list the contents of a zipfile and add them into a treemap just say the first directory and then the next sub directory and file so I can see how
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How are you with recursion? It's really only a half-dozen/dozen lines of code to create the map entries from each path.
Shawn Franks
Greenhorn

Joined: May 18, 2010
Posts: 23
I'm fine with recursion.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

So... if the map entry for the path element doesn't exist, create it. Pass the remaining path elements to the function (the recursive part), repeat until it's empty.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18997
    
    8

Shawn Franks wrote:If possibly you could show a little example of what you would do to list the contents of a zipfile...

This is the part you should start with. Don't worry about data structures, just dump the list of contents to the console for a start. Don't try to eat the whole elephant at one sitting.
Shawn Franks
Greenhorn

Joined: May 18, 2010
Posts: 23
I understand that much but my problem is I don't understand how to do the dynamic part of the tree. For instance if I mae a tree as treemap<string, string> abc = new treemap<string,string> and add the first directores and sub directories how do I add the next set because the tree is set for string string
Shawn Franks
Greenhorn

Joined: May 18, 2010
Posts: 23
I know how to dump the contents that's not the issue. I need to structure it
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It wouldn't *be* String, String--as I said previously, it'd be String, Map (or if I were doing it I might do String, MyMapClass)
Shawn Franks
Greenhorn

Joined: May 18, 2010
Posts: 23
Would string string map work?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not sure what that means, you only get key and value types?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a TreeMap form Enumerated Zip Entries