格式错误的 URLException
MalformedURLException
这是一种将页面源代码转换为字符串数组和 return 该数组的方法,但由于某种原因,我不断收到异常错误。
当我尝试使用这个 class 它 return 是我 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;
}
您正在将字符串 "A"
作为参数传递给 URL 构造函数 new URL("A");
。 "A"
不是有效的 URL。
我认为您打算将变量 A 传递给它,对吗?删除 " "
.
这是一种将页面源代码转换为字符串数组和 return 该数组的方法,但由于某种原因,我不断收到异常错误。
当我尝试使用这个 class 它 return 是我 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;
}
您正在将字符串 "A"
作为参数传递给 URL 构造函数 new URL("A");
。 "A"
不是有效的 URL。
我认为您打算将变量 A 传递给它,对吗?删除 " "
.