未处理的异常java.net.malformedurlexception

Joh*_*ohn 6 java url

为什么这段代码unhandled exception java.net.malformedurlexception在java中给我一个?

String u = "http://webapi.com/demo.zip";
URL url = new URL(u);
Run Code Online (Sandbox Code Playgroud)

有人能告诉我如何解决?

Ger*_*hes 7

你需要处理可能的异常.

试试这个:

    try {
        String u = "http://webapi.com/demo.zip";
        URL url = new URL(u);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)