这是一种将页面源代码转换为字符串数组并返回该数组的方法,但出于某些原因,我一直会收到异常错误。
当我尝试使用这个类时,它会返回java.net.MalformedURLException:没有协议
我处理了例外情况,我不明白。有谁能给我解释一下为什么我老是犯这个错误吗?
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;
}发布于 2017-03-22 14:57:13
您将字符串"A"作为参数传递给new URL("A");构造函数。"A"不是有效的网址。我想你打算把它传递给变量A,对吗?删除" "。
https://stackoverflow.com/questions/42955228
复制相似问题