Name: dgC58589 Date: 01/07/98
I'm an old Unix hacker. I grew up with forward
slashes separating levels in a path. I'm trying
to avoid becoming a Windows hacker by becoming a
Java hacker. But unfortunately, the separator
character is being treated inconsistently in
java.io (and awt). I lived with it in jdk1.1, but
its time to make some noise... the inconsistency
is causing me too much pain. :o)
For instance: if I create a File with a path
in a string with forward-slash separated levels
and open it (let's say by creating a
RandomAccessFile) everything's cool. That is
until I do a getParent() on the File; instead of
using the forward slashes, its using the native
separatorChar. Yack. (I've had to do some fairly
ugly path munging in subclasses of java.io to get
things to hand off in a platform independent way;
it works, but its not transparent.)
Or how about this: pass a mkdirs() message to a
File created with a forward slash separated
levels which needs a few levels of directory
created on Windows95:
boolean createdDirectories =
(new File("C:/foo/bar/mumble/theFile")).
mkdirs();
Check out different values for the expression
when either nothing, only foo, foo/bar,
foo/bar/mumble, or foo/bar/mumble/theFile exist.
If there's no security violation, all of the
calls should create whatever's necessary (even if
nothing had to be created) and return true.
Because of the inconsistency with the forward
slashes, mkdirs doesn't work unless you first
convert the path to an machine-dependent
representation. Yack again. Java should do this.
The problem is that Java should either do it all
everywhere (converting to a universal separator -
might I suggest a forward slash?) or make the
developer do it all (dealing with all of the
platform dependencies.) Doing only some of it and
making the developer discover (by trial and
error) what works and what doesn't is a real
pisser.
Or, at least as a stopgap add pathNormalize() and
pathUnnormalize() to file so the filtering is in
the right object.
(Review ID: 22667)
======================================================================
- duplicates
-
JDK-4117370 java.io.File.getParent cannot handle mixed slashes
-
- Closed
-
- relates to
-
JDK-4131169 java.io.File: Respecify using abstract pathnames rather than strings
-
- Closed
-