Detect System Drive

Is there a class/method in java to detect the system drive of the user's computer.  This only has to work for Windows based PCs.  Basically I just need to know the letter (i.e. C:)

LVL 18
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

File[] fdrives=File.listRoots();
--> you will get an array of File, for example:
   A:\ C:\  D:\
(A:\ maybe only if you have inserted a disk in the drive)
just tested :  A:\ is listed even without disk in drive
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

mgcITAuthor Commented:
that's just a list of drives on the system though right?  How do I detect the Windows System drive?
It's the same as your profile drive, so :

    String s=System.getProperty("user.home");
    // -> something like C:\Documents and Settings\yourname

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
only the drive letter :
Otherwise, you can use environment variables : CommonProgramFiles, HOMEDRIVE, HOMEPATH, ProgramFiles, SystemDrive, SystemRoot, TEMP, windir

  -  with Java 1.5.0   System.getenv("SystemDrive");
  -  older versions : you have to use command line arguments:
               java ... -DSystemDrive=%SystemDrive% <yourclass>

Mick BarryJava DeveloperCommented:
You coulkd use listRooots() and then loop thru them looking for which one has a Windows directory
>> You coulkd use listRooots() and then loop thru them looking for which one has a Windows directory
You have to check "WinNT" and "Windows" directories.
Cannot work when you have multiple versions of Windows installed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.