A couple more options:
A call to the # getCanonicalPath file occurs to remove the slashes, but it seemed to use this stack inside:
at java.io.UnixFileSystem.canonicalize0(Native Method) at java.io.UnixFileSystem.canonicalize(UnixFileSystem.java:172) at java.io.File.getCanonicalPath(File.java:618)
which seemed actually pretty slow (at least on our particular system, which was Linux with GPFS below), so I couldn't use that.
So, I tried from Aubin's remote answer (thanks for saying that he might have seen in the JDK somewhere), it was actually pretty fast:
path = new File( new File( path ).toURI().normalize()).getPath();
Unfortunately, under the toURI method, it seemed like this:
at java.io.UnixFileSystem.getBooleanAttributes0(Native Method) at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:242) at java.io.File.isDirectory(File.java:843) at java.io.File.toURI(File.java:732)
which was, again, a little slowdown.
See also java nio Paths # normalize
So, at the end of the day, I ended up using replaceAll methods from others.
source share