• Post Reply Bookmark Topic Watch Topic
  • New Topic

View Hard Disk Drives in Java

 
abu alfouz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

How can I see the drives of the machine (C:, D:, ..) through java program?

Thank you.
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by abu alfouz:
Hi

How can I see the drives of the machine (C:, D:, ..) through java program?

Thank you.


Do you mean accessing Drives(like in other application Open Dialog for selecting files).If that is the case you have JFileChooser in java
[ December 27, 2007: Message edited by: Balasubramanian Chandrasekaran ]
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check File.listRoots()
 
abu alfouz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, but I mean to know (in the code) that this machine for example has 2 drives (C: and D then those drives as folders.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you actually look at using the File method listRoots()?

Why is the result of listRoots() not helping you solve this problem?

Bill
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it does have the problem of also listing floppy drives and optical drives.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point Rob - so naturally I had to try it - here is what I ran:



And here is what it produced:

Try to execute DriveCheck
Found 10 roots
A:\ exists= false
C:\ exists= true
D:\ exists= true
E:\ exists= false
F:\ exists= false
G:\ exists= false
H:\ exists= false
I:\ exists= false
Y:\ exists= true
Z:\ exists= true
Done

A - the floppy - did not have a disk in at the time
C and D are my only hard disk roots
E - optical drive with nothing in it
F, G, H, I - for some reason this computer shows these but there is not drive there
Y and Z are directories elsewhere on the network mapped to drives by the OS

Now I am wondering if there is an OS command we could exec() to find out more about each.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!