• 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

Files.walkFileTree probelm

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I got over 10 000 files in irregular 500 files, I need to find 1 file (more then 1 times)
I worte a program using nio Files.walkFileTree



but it working too slow,
which another class can I use to make it work faster?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The process is a slow one.  But you can help yourself by printing progress updates.  First, add two fields:
The divisor may be different depending on how fast your computer is.  Lower the divisor for faster display; raise it for slower.  Now add this to your postVisitDirectory() method:
You'll get a display of the folder that the program is currently processing.  
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm not sure how much of a speed improvement this would make, but you are calling toAbsolutePath() twice. In the first case you are populating "fileString" and then using endsWith() against that. If you only need to find the file name and not the name plus part of the path then the first call to toAbsolutePath() is overkill, you don't actually care what the "path" is, only the file name. Only when you've determined that you've found the file you're looking for, then call toAbsolutePath().

This is one of those cases where I'd have to convince myself that this approach is faster (at least not slower) than writing a recursive search method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic