URL Creation
In this chapter you will learn:
Creating a URL with a single string
The following code creates a URL from single string.
import java.net.URL;
/*from j a va 2 s.c om*/
public class Main {
public static void main(String[] argv) throws Exception {
URL url = new URL("http://java2s.com:80/index.html");
System.out.println(url);
}
}
The code above generates the following result.
Creating a URL With components
The following code creates a URL from each component passes in as different parameters.
import java.net.URL;
/*from j a v a 2 s .c om*/
public class Main {
public static void main(String[] argv) throws Exception {
URL url = new URL("http", "java2s.com", 80, "/index.html");
System.out.println(url);
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » URL URI