How to use class URL?

Ma Xiaoguang maxiaoguang10000 at hotmail.com
Sat Jan 4 09:04:27 UTC 2014


Hello everyone,

Happy new year!

Hope this is not a wrong place to post. If I am wrong, please point me to 
the proper place. Thanks.

My JDK version is 1.6.0_35 . I wrote the following code:

----------------------------------
import java.net.*;

public class URLTest {

    public static void main(String[] args) {
        try {
            URL url = new URL("www.yahoo.com");
            String s = url.getHost();
            System.out.println(s);
        } catch (Exception e) {
            System.out.println("Error Occur!");
        }
    }
}
------------------------------------------

and I compile and run the above code in the comand-line of Windows XP 
Professional like this:

javac URLTest.java
java URLTest

the result is: Error Occur!

How to use the URL class? Thanks in advance.

Best regards,

Ma Xiaoguang






More information about the discuss mailing list