The javadoc states that File.pathSeparatorChar :
System-dependent path separator character. This field is initialized to contain the first character of the value of the system.separator property. This symbol is used to separate file names in a sequence of files specified as a list of paths. On UNIX systems, this symbol:; on Microsoft Windows systems this ; .
But this seems strange, because the semicolon is not a forbidden character for Windows paths (for links, this is \ / : * ? " < > | , Cf is the Windows Explorer rename function).
For example, with the following code:
String test = "C:\\my;valid;path" + File.pathSeparator + "C:\\Windows"; String[] tests = test.split(File.pathSeparator);
tests will contain C:\\my valid path C:\\Windows , which was not expected.
So the question is: why is this character not a colon, as on Unix? I could force my code to use a colon, but that seemed to exceed the goal of having a constant in the JDK.
Edit: Reimeus explained why it cannot be a colon on Windows (it's a disk separator), but what I'm really interested in is the reason that it is not a character that cannot appear in the path, such as | .
source share