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:)

Thanks
LVL 18
mgcITAsked:
Who is Participating?

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

x
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.

WebstormCommented:
File[] fdrives=File.listRoots();
WebstormCommented:
--> you will get an array of File, for example:
   A:\ C:\  D:\
(A:\ maybe only if you have inserted a disk in the drive)
WebstormCommented:
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?
WebstormCommented:
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
WebstormCommented:
only the drive letter :
   s.substring(0,2);
WebstormCommented:
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>
               System.getProperty("SystemDrive");


Mick BarryJava DeveloperCommented:
You coulkd use listRooots() and then loop thru them looking for which one has a Windows directory
WebstormCommented:
>> 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
Java

From novice to tech pro — start learning today.