This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

zip to JTree  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Anybody know any method to explore a zip file and convert their content to a JTree?

Thank you very much.
 
Sheriff
Posts: 21747
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you know how to read all entries in a Zip file.

I would keep a mapping from entry names to DefaultMutableTreeNodes. Then, when you encounter a ZipEntry, you determine its parent from the name (using the / as the separator*). You retrieve the parent node from the map, creating it if necessary. Then you create a DefaultMutableTreeNode, and add it to the parent node. Finally you add the new mapping.

In pseudo code (untested):

* You can be lazy and use java.io.File for this.
 
Iban Cardona
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Prime wrote:I assume you know how to read all entries in a Zip file.

I would keep a mapping from entry names to DefaultMutableTreeNodes. Then, when you encounter a ZipEntry, you determine its parent from...



Thank you.

Using split would be a good solution for the name of the parent?
 
Rob Spoor
Sheriff
Posts: 21747
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can get the right regex, sure. Not that that's too hard
 
Iban Cardona
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George,

Many thanks. Helped me a lot.
I made a small test and seems to work pretty well. I show you the code adapted to my needs.



What do you think?
Many thanks again.
 
Rob Spoor
Sheriff
Posts: 21747
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will cause problems if you happen to have a zip entry with the same name as the value of nomFitxer.
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!