• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to save the directory structure to ArrayList ?

 
benny rusli
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
benny rusli
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic