URI (@NotNull File file) { String path = file.getAbsolutePath(); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); if (!path.startsWith("/")) path = '/' + path; if (path.startsWith("//")) path = "//" + path; try { return new URI("file", null, path, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(path, e); // unlikely, as `File#toURI()` doesn't declare any exceptions } }