How to programmatically get Java classpath separator used in value of java -cp/-classpath option?
System property path.separator contains classpath separator for current platform. It can be obtained by
System.getProperty("path.separator");
From System.getProperties() documentation:
path.separator Path separator (":" on UNIX)
Values are : for Linux and Mac OS, ; for Windows.
For this purpose, you can rely on the constant File.pathSeparatorChar if you expect a char or File.pathSeparator if you expect a String.
I quote the Javadoc of File.pathSeparatorChar:
The system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With