This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to save the directory structure to ArrayList ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to save the directory structure to ArrayList ?" Watch "how to save the directory structure to ArrayList ?" New topic
Author

how to save the directory structure to ArrayList ?

benny rusli
Ranch Hand

Joined: Jan 15, 2005
Posts: 72
Hello people,

i want to know how save the directory structure to ArrayList, and then later i can iterate it, so that the double path or the double string remove and then i will zip the directory with the ZipOutputStream class (of course i give the path to FileInputStream and write it to ZipOutputStream). Which one is better : ArrayList, TreeSet, Vector, List, etc from Collection class ? Can someone give an example how to figure it, any help would be appreciated ?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think you'll find you can walk the directory structure and write the files in a single path rather than walk it once to get directory names and walk those to write files. Have you looked at all the methods on File? You'll need a recursive routine something like:

That's not real Java of course ... let me know if it is close enough to get you started coding.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
benny rusli
Ranch Hand

Joined: Jan 15, 2005
Posts: 72
Hello people,

thanks for replaying my question, i want to save the path of directory to List Collection because i want to avoid the double entry name such as c:\java\example.txt could occur two time if i zip a large of directory and file(more than 2 GB). And the second reason i want to obtain the directory structure. Have anyone better solution than i have gotten, here is my code :



Another solution would be appreciated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to save the directory structure to ArrayList ?
 
Similar Threads
about accesing js function in JSP
Servlet-File-Upload
zip files without path info...
Problem When Compressing Directory
java.util.zip : Unzipping gives Windows error