The javadoc states that File.pathSeparatorChar
is:
The system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is
:
; on Microsoft Windows systems it is;
.
But that seems strange, because a semicolon is not a forbidden character for Windows paths (for references, those are \
/
:
*
?
"
<
>
|
, cf the rename feature of Windows Explorer).
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 isn't what it'd expect.
So the question is: why isn't this character a colon, like on Unix? I could force my code to use a colon, but that seems to defeat the purpose of having a constant in the JDK.
Edit: Reimeus explained why it can't be a colon on Windows (it's the drive separator), but what I'm really interested in is the reason why it's not a character that can't appear in a path, such as |
.
;
, it needs to be wrapped in quotes in the path list. This seems reasonable, even though you then can't usesplit
to split the path list into parts. – Lubberly