How to get the root directory ?

A

Abs

Hi!

I know how to get the user home directory with
System.getProperty("user.home"), but I cannot find any
system property to get the root directory in a file
tree. You know, the "My PC" in Windows or the "/" directory
in Unix. Is it possible with java ?


thanx
 
A

ak

I know how to get the user home directory with
System.getProperty("user.home"), but I cannot find any
system property to get the root directory in a file
tree. You know, the "My PC" in Windows or the "/" directory
in Unix. Is it possible with java ?

FileSystemView.getFileSystemView().getHomeDirectory()

or

FileSystemView.getFileSystemView().getRoots()[0];

____________

http://reader.imagero.com the best java image reader.
 
C

Chris Smith

Abs said:
I know how to get the user home directory with
System.getProperty("user.home"), but I cannot find any
system property to get the root directory in a file
tree. You know, the "My PC" in Windows or the "/" directory
in Unix. Is it possible with java ?

The "My Computer" pseudo-directory in Windows is not a real directory at
all... just a convention of sorts, so it's a little difficult to know
what you mean by "getting" it. You can get real filesystem roots with
the File class's static listRoots method. For Windows, though, that
will return the roots of all drives, not "My Computer".

If you're planning on displaying this to the user, as in a file
selection control, Swing provides a class called
javax.swing.filechooser.FileSystemView. You can get one through a
static factory method in that class. That class provides the virtual
sort of pseudo-filesystem that's actually presented to the user on most
Windows systems, along with things like conventional icons, human-
readable type descriptions, and other things that are useful for
providing a human interface to the filesystem.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top