How to use Java pathSeparator,pathSeparatorChar
path separator using in Unix systems is colon(:) while in windows it is semicolon (;).
Due to this differences if setting up PATH or CLASSPATH for one environment will not work on other environment, overcome these issues and work platform independent way, java introduced pathSeperator variable.
The value of pathSeparatorChar is same as File.pathSeparator, but it will be a char rather than a string. So the output for File.pathSeparatorChar is colon(:) for unix and semicolon (;) for windows.
Real examples
/path/to/jar1.jar:/path/to/jar2.jar:/path/to/jar3.jar (for unix) C:\Java\jdk1.7.0\bin;C:\Windows\System32\;C:\Windows\ (for windows)
File.pathSeparator Usage
import java.io.File; public class FilePathSeparatorExample { public static void main(String[] args) { System.out.println("File.pathSeparator = "+File.pathSeparator); System.out.println("File.pathSeparatorChar = "+File.pathSeparatorChar); } }
output for linux
File.pathSeparator = : File.pathSeparatorChar = :
output for windows
File.pathSeparator = ; File.pathSeparatorChar = ;
1 Responses to "How to use Java pathSeparator,pathSeparatorChar"