• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help improve this code without the use of HashMap

 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Winston
I will check that out. Thanks for your availability.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Winston
Your hint led me to this:
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Ngom wrote:Your hint led me to this:


OK, well Path has a toFile() method, and File has a toPath() method, so you can easily convert between the two. I think I've given you enough to get to your own solution. The important thing is to understand how that trawl() method works; don't just parrot the code. Otherwise, you'll be back as soon as you need to do something slightly different.

So, if you haven't already, get out a pencil and paper and write down what it does with a few sample file names. You don't need to be exhaustive, but do a few levels, so that you understand what's going on.
Unless you come from a pure maths background, recursion can be very difficult to "visualise". As I said previously, I've been at this lark a long time, and I still have to think hard about it.

HIH

Winston
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now that i have two working programs, i will have to choose one. The code i posted first runs pretty faster if i remove the file i/o.
Anybody else who could share with us another way to achieve this. I mean listing all sub folders of a given directory no matter their level in the tree structure.
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always create a new File object from the current File's Canonical Path, then a new File object from the current File's Absolute Path, and then check if they are equal. Suspect NTFS is not gonna play nice with that though.


For simplicity and speed, I would hazard that Files.walkFileTree is going to give you some decent performance. Depending on how lightweight your visitor is.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


For simplicity and speed, I would hazard that Files.walkFileTree is going to give you some decent performance.



Hi Dieter,
Could you please post a simple code about how this could be achieved? Thanks in advance.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic