2

How can we code in java to find out the drive letter on which operating system is installed ?

FullStack
  • 665
  • 11
  • 26
  • 7
    Are you aware that there are operating systems that do not follow the "Windows Drive Letter Concept"? Is this supposed to work on Windows only? – reto Feb 24 '14 at 10:30
  • Yes, i am looking it for windows only. – FullStack Feb 24 '14 at 10:31
  • 2
    @reto not really a duplicate because it uses the win32 api. Can't be called as is from java, you would need a JNI call. – assylias Feb 24 '14 at 10:33
  • @assylias you do have a point there, the most voted answer is however referring to the same system env. variable – reto Feb 24 '14 at 10:37
  • 1
    Once upon a time the operating system used to be on the A: drive but that was long before windows. Do you ever see users installing on a drive other than C: ? – Peter Lawrey Feb 24 '14 at 10:50

1 Answers1

10

You can get that from the Environment:

System.getenv("SystemDrive");
user432
  • 3,506
  • 17
  • 24