wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to identify classpath separator for a specific OS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to identify classpath separator for a specific OS" Watch "How to identify classpath separator for a specific OS" New topic
Author

How to identify classpath separator for a specific OS

Kjeld Sigtermans
Ranch Hand

Joined: Aug 10, 2006
Posts: 125
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: 39791
    
  28
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: 125
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: 39791
    
  28
You're welcome
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

These are also available as constants in java.io.File, both as String and as char.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kjeld Sigtermans
Ranch Hand

Joined: Aug 10, 2006
Posts: 125
Ah yes this might be a little more convenient! Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Yes, I forgot they were in File.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to identify classpath separator for a specific OS