奇怪的readLine()
import java.net.URL;
import java.net.MalformedURLException;
import java.io.*;
import java.net.MalformedURLException;
import java.io.*;
class Test{
public static void main(String args[]){
URL root=null;
URL url=null;
String readstring;
DataInputStream dis;
try{
root=new URL("http://localhost/");
url=new URL(root,args[0]);
dis=new DataInputStream(url.openStream());
while ((readstring =dis.readLine())!=null){
System.out.println(readstring);
}
System.out.println("***************** end of the file***********");
dis.close();
}catch(MalformedURLException e){
System.out.println("MalformedURLException:"+e);
}
catch(IOException e){
System.out.println("IOException:"+e);
}
}
}
public static void main(String args[]){
URL root=null;
URL url=null;
String readstring;
DataInputStream dis;
try{
root=new URL("http://localhost/");
url=new URL(root,args[0]);
dis=new DataInputStream(url.openStream());
while ((readstring =dis.readLine())!=null){
System.out.println(readstring);
}
System.out.println("***************** end of the file***********");
dis.close();
}catch(MalformedURLException e){
System.out.println("MalformedURLException:"+e);
}
catch(IOException e){
System.out.println("IOException:"+e);
}
}
}
运行后提示:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Test.main(Test.java:13)
at Test.main(Test.java:13)