public static Path uriToPath(URI uri) { Path thePath = null; if (Sys.isWindows()) { String newPath = uri.getPath(); if (newPath.startsWith("/C:")) { newPath = slc(newPath, 3); } thePath = FileSystems.getDefault().getPath(newPath); } else { thePath = FileSystems.getDefault().getPath(uri.getPath()); } return thePath; }
private static String getWindowsPathIfNeeded(String path) { if (Sys.isWindows()) { if (!path.startsWith("http") && !path.startsWith(CLASSPATH_SCHEMA) && !path.startsWith(JAR_SCHEMA)) { path = path.replace('/', Sys.windowsPathSeparator()); if (slc(path, 0, 6).equals("file:\\")) { path = slc(path, 6); } } if (path.startsWith(".\\")) { path = slc(path, 2); } } return path; }
public static URI createURI(final String path) { if (!Sys.isWindows()) { return URI.create(path); } else { if (path.contains("\\") || path.startsWith("C:") || path.startsWith("D:")) { String newPath = new File(path).toURI().toString(); if (newPath.startsWith("file:/C:")) { newPath = slc(newPath, 8); return URI.create(newPath); } else { return URI.create(newPath); } } else { return URI.create(path); } } }