Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to identify classpath separator for a specific OS

 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are also available as constants in java.io.File, both as String and as char.
 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah yes this might be a little more convenient! Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I forgot they were in File.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic