Getting the default root directory in Java

后端 未结 2 608
甜味超标
甜味超标 2021-02-19 17:55

I\'m making a basic file browser, and want to know how to get the default root directory. I know that java.io.File.listRoots() gives all the roots (for me it\'s

2条回答
  •  眼角桃花
    2021-02-19 18:29

    Getting the operating system root partition is only a thing on Windows since on Unix it's always /.

    Hence, the following code works for Windows only:

    System.getenv("SystemDrive");
    

    It gets the SystemDrive environment variable value. This should always return the operating system's root partition e.g. C:.

提交回复
热议问题