Here you can find the source of toURI(String path)
public static URI toURI(String path)
//package com.java2s; import java.net.URI; public class Main { public static URI toURI(String path) { return URI.create(treatPath(path)); }//from w w w. j a v a 2 s. c o m public static String treatPath(String path) { if (path != null && !path.trim().isEmpty()) { final String uriSuffix = "file:"; final String slash = "/"; path = path.trim(); path = path.replaceAll("//", slash); path = path.replaceAll("\\\\", slash); path = path.replaceAll("\\s+", " "); path = path.replaceAll("[\\p{Z}]", "%20"); StringBuilder sb = new StringBuilder(); if (!path.startsWith(uriSuffix)) { if (path.startsWith(slash)) { sb.append(uriSuffix).append(path); } else { sb.append(uriSuffix).append(slash).append(path); } } return sb.toString(); } return path; } }