4

How to programmatically get Java classpath separator used in value of java -cp/-classpath option?

2 Answers 2

16

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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 ';'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.