| Author |
How to identify classpath separator for a specific OS
|
Kjeld Sigtermans
Ranch Hand
Joined: Aug 10, 2006
Posts: 111
|
|
Hi, I am reading the classpath using System.getProperty("java.class.path") and I am trying to analyze each entry using a tokenizer. I noticed that in Windows the classpath entries are separated by a ';', and in Unix it's a ':' (I noticed this in Ubuntu Linux). Does anyone know how to identify the classpath separator for a specific OS/file system? Kind regards, Kjeld
|
Kjeld Sigtermans - SCJP 1.4 - SCWCD 1.4
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
Go through the java.lang.System class, and there is a method called something like getProperties. That returns a Properties object, which has methods like list. Using that method you should be able to get a listing of all Properties; there will be one called something like path.separator. Now back to the System class and use getProperty("path.separator") only you use the correct spelling.
|
 |
Kjeld Sigtermans
Ranch Hand
Joined: Aug 10, 2006
Posts: 111
|
|
Thanks. path.separator and file.separator are the ones I was looking for. I used them once before, but just couldn't remember how I did that:-)
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
You're welcome
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
These are also available as constants in java.io.File, both as String and as char.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Kjeld Sigtermans
Ranch Hand
Joined: Aug 10, 2006
Posts: 111
|
|
|
Ah yes this might be a little more convenient! Thanks
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
Yes, I forgot they were in File.
|
 |
 |
|
|
subject: How to identify classpath separator for a specific OS
|
|
|