The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.net  [27 examples] > URLs  [8 examples]

e133. Converting Between a URL and a URI

    URI uri = null;
    URL url = null;
    
    // Create a URI
    try {
        uri = new URI("file://D:/almanac1.4/Ex1.java");
    } catch (URISyntaxException e) {
    }
    
    // Convert an absolute URI to a URL
    try {
        url = uri.toURL();
    } catch (IllegalArgumentException e) {
        // URI was not absolute
    } catch (MalformedURLException e) {
    }
    
    // Convert a URL to a URI
    try {
        uri = new URI(url.toString());
    } catch (URISyntaxException e) {
    }

 Related Examples
e132. Creating a URL
e134. Parsing a URL
e135. Sending a POST Request Using a URL
e136. Getting Text from a URL
e137. Getting an Image from a URL
e138. Getting a Jar File Using a URL
e139. Accessing a Password-Protected URL

See also: Datagram    Encodings    HTTP    Hostnames and IP Addresses    Multicast    Sockets   


© 2002 Addison-Wesley.