0

这是一种将页面源代码转换为字符串数组并返回该数组的方法,但由于某种原因,我不断收到异常错误。

当我尝试使用此类时,它返回我 java.net.MalformedURLException: no protocol

我处理了异常,我不明白。有人可以向我解释为什么我不断收到此错误吗?

 public static String[] Connect(String A) throws IOException,
    MalformedURLException {
    ArrayList<String> myList = new ArrayList<String>();
    URL url = new URL("A");
    URLConnection spoof = url.openConnection();


    spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
    BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
    String strLine = "";

    while ((strLine = in.readLine()) != null){
        myList.add(strLine);
        System.out.println(strLine);
    }
    String[] arr = myList.toArray(new String[myList.size()]);
    return arr;

}
4

1 回答 1

0

您将字符串"A"作为参数传递给 URL 构造函数new URL("A");"A"不是有效的 URL。我认为您打算将变量 A 传递给它,对吗?删除" ".

于 2017-03-22T14:57:13.067 回答