aspose file tools
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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: 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
    
    4
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
    
    4
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
    
    4
Yes, I forgot they were in File.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to identify classpath separator for a specific OS
 
Similar Threads
To K&B from my sincere to your Head First EJB book.
jdbc connection
need basic help to compile first servelet
J2EE RI for a Mac
Environment Variable!!