aspose file tools*
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
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to save the directory structure to ArrayList ?