Here you can find the source of toURI(String location)
public static URI toURI(String location) throws URISyntaxException
//package com.java2s; //License from project: Apache License import java.net.URI; import java.net.URISyntaxException; import java.net.URL; public class Main { public static URI toURI(URL url) throws URISyntaxException { return toURI(url.toString()); }//from w w w. java 2 s.c o m public static URI toURI(String location) throws URISyntaxException { return new URI(location.replace(" ", "%20")); } }