在URL和URI之间转换
import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; /** 来 自 N o w J a v a . c o m - 时 代 Java **/ public class Main { public static void main(String[] args) { URI uri = null; URL url = null; // Create a URI try { uri = new URI("file://D:/folder/Ex1.java"); } catch (URISyntaxException e) { } // Convert an absolute URI to a URL try { url = uri.toURL(); } catch (IllegalArgumentException e) { // URI was not absolute /** * n o w j a v a . c o m 提 供 **/ } catch (MalformedURLException e) { }