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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 122
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: 38075
    
  22
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: 122
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: 38075
    
  22
You're welcome
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

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: 122
Ah yes this might be a little more convenient! Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
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
 
Similar Threads
J2EE RI for a Mac
jdbc connection
Environment Variable!!
need basic help to compile first servelet
To K&B from my sincere to your Head First EJB book.