Skip to content

Commit bf03041

Browse files
committed
Fix FileUtils#urlToFile() on Windows
Under certain circumstances, on Windows, URLs are translated into strings of the form "file:C:/..." (which the URL constructor does not like at all) instead of "file:/C:/..." (which the URL constructor does like). Let's be lenient on Windows and just accept even the first form. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0693a81 commit bf03041

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/org/scijava/util/FileUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public final class FileUtils {
6666
public static final String SHORTENER_SLASH = "/";
6767
public static final String SHORTENER_ELLIPSE = "...";
6868

69+
private final static boolean isWindows =
70+
System.getProperty("os.name").startsWith("Win");
71+
6972
private FileUtils() {
7073
// prevent instantiation of utility class
7174
}
@@ -204,6 +207,9 @@ public static File urlToFile(final String url) {
204207
path = path.substring(4, index);
205208
}
206209
try {
210+
if (isWindows && path.matches("file:[A-Za-z]:.*")) {
211+
path = "file:/" + path.substring(5);
212+
}
207213
return new File(new URL(path).toURI());
208214
}
209215
catch (final MalformedURLException e) {

0 commit comments

Comments
 (0)