Get Object from a Valid URL using URL class in java :
import java.net.MalformedURLException;
import java.net.URL;
public class getobject {
public static void main(String args[]) {
URL resourceURL;
if(args.length > 0) {
try {
resourceURL = new URL(args[0]);
try {
Object o = resourceURL.getContent();
System.out.println("Content
in This URL is " + o.getClass().getName());
} catch(Exception e) {
System.err.println(e);
}
} catch(MalformedURLException
e) {
System.err.println(args[0]
+ "
is not a parseable URL");
System.err.println(e);
}
}
}
}
If the URL passed as a parameter tends to be correct object will get retrieved.
No comments:
Post a Comment