Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help improve this code without the use of HashMap

 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
@Winston
Your hint led me to this:
 
Winston Gutkowski
Bartender
Pie
Posts: 10083
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic