aspose file tools*
The moose likes Performance and the fly likes Slow performance on method retrieving available drives of PC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Slow performance on method retrieving available drives of PC" Watch "Slow performance on method retrieving available drives of PC" New topic
Author

Slow performance on method retrieving available drives of PC

Joshua Ebarvia
Ranch Hand

Joined: Sep 25, 2007
Posts: 70
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


[Thumbnail for profiling.png]



Lovin' java
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
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

Joined: Sep 25, 2007
Posts: 70
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,


[Thumbnail for profiling.png]

Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
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

Joined: Sep 25, 2007
Posts: 70
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

Joined: Jun 01, 2010
Posts: 618
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

Joined: Sep 25, 2007
Posts: 70
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
 
subject: Slow performance on method retrieving available drives of PC