My java code is below.I wrote url=URL(s); but it is not true.I want to make a casting operation to convert a string that is taken from the user ,to an URL.How can I do this operation?Is there any method to do this?
public static void main(String[] args) {
System.out.println("Welcome to Download Manager");
URL url;
String s;
Scanner scan= new Scanner(System.in);
s=scan.nextLine();
url=URL(s);
Download download=new Download(url);
}
You can't cast String to URL, since String is not a subclass of URL. You can create new instance of URL, passing String as argument to the constructor. In Java, you always invoke constructor using keyword new:
URL url = new URL(string);
Using the URL constructor:
url = new URL(s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With