I wonder how can I get a current volume using Java?
For example:
C:\
or D:\
or on Unix.
I wonder how can I get a current volume using Java?
For example:
C:\
or D:\
or on Unix.
Use either:
File currDir = new File(".");
or as @JigarJoshi, more or less, stated:
File currDir = new File(System.getProperty("user.dir", "."));
which defaults to the first solution when the property is not set.
To obtain the root volume:
Path root = currDir.toPath().getRoot();
Try this:
String currentPath = new File(".").getAbsoluteFile().toString();
for (File f : File.listRoots()) {
if (currentPath.startsWith(f.toString())) {
System.out.println(f);
}
}