File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Slow performance on method retrieving available drives of PC

 
Joshua Ebarvia
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day fellows,

I have been doing a code that would retrieve available drive letters of a windows PC.

Here is my method


The problem is that it takes 5549ms to complete the method call (I have attached a profiler picture)

Is there something wrong with my code? How do I make it fast?

Regards
profiling.png
[Thumbnail for profiling.png]
 
Tom Reilly
Rancher
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a File.listRoots() method. Have you tried that? My guess is that the way you are doing it, the slowness is when you query the drives that don't exist. Can you change the code so that you can time each query rather than all 26 at once?
 
Joshua Ebarvia
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Reilly wrote:There is a File.listRoots() method. Have you tried that? My guess is that the way you are doing it, the slowness is when you query the drives that don't exist. Can you change the code so that you can time each query rather than all 26 at once?


I have changed my method and used File.listRoots() as you have suggested, then I run the profiler once more.

Here is the new code


I don't know why it is still running very slow...

Regards,
profiling.png
[Thumbnail for profiling.png]
 
Tom Reilly
Rancher
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the size of your File array after you call File.listRoots()? What is the linesupposed to do? It looks like you are creating new instances of File rather than using the ones returned by File.listRoots(). What is the output from running this method? Does it return true or false?
 
Joshua Ebarvia
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the result of the method is "true" - because i have created a folder filestorage on drive C:

The reason for the line
is because my application will search for the drive of the computer which contains the folder filestorage..
Hence, I have appended the string "filestorage" to the result of the File.listRoots().

Is there any other way to do the appending without creating a new instance of File?

Thanks once again

 
Tom Reilly
Rancher
Posts: 618
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a System.out.println(file[i].getAbsolutePath()); What is the output when you run the test? Here's an ancient question: does your computer have a floppy drive that File.listRoots() recognizes as the A: drive? Come to think of it, your original code started by looking for the A: drive. The floppy drive is notoriously slow. I guess another question is does File.listRoots() return the File instances in order (C: drive before D drive)? Since the test returns true, I'm guessing that file[i] + "filestorage" returns C:\filestorage (and path delimiters is not the problem).
 
Joshua Ebarvia
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Reilly wrote:You have a System.out.println(file[i].getAbsolutePath()); What is the output when you run the test? Here's an ancient question: does your computer have a floppy drive that File.listRoots() recognizes as the A: drive? Come to think of it, your original code started by looking for the A: drive. The floppy drive is notoriously slow. I guess another question is does File.listRoots() return the File instances in order (C: drive before D drive)? Since the test returns true, I'm guessing that file[i] + "filestorage" returns C:\filestorage (and path delimiters is not the problem).


Thank you very mych, the main problem is the access of the A: which is very slow...




Thank you once again
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic