Here you can find the source of toUri(String path)
public static URI toUri(String path)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.net.URI; import java.net.URISyntaxException; public class Main { public static URI toUri(String path) { if (path == null || path.isEmpty()) { return null; }/*from ww w .jav a2 s . co m*/ File file = new File(path); if (file.exists()) { path = file.getAbsolutePath(); } URI uri; try { uri = new URI(path.replace('\\', '/')); } catch (URISyntaxException e) { throw new RuntimeException(e); } return uri.normalize(); } }