这是一种将页面源代码转换为字符串数组并返回该数组的方法,但由于某种原因,我不断收到异常错误。
当我尝试使用此类时,它返回我 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;
}