java网络编程基础问题,求大神讲解下
package getContent;
import java.net.*;import java.io.*;
public class GetContent {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
URL url = new URL("这里网站地址,不能写,不然违规");
URLConnection uc= url.openConnection();
byte[] htmlByte = new byte[uc.getContentLength()];
DataInputStream fi = new DataInputStream(uc.getInputStream());
while(fi.read()!=-1){
fi.read(htmlByte);
System.out.println(new String(htmlByte));
}
fi.close();
}
}
java运行问题,为什么运行要报错,那些写错了吗,写的是byte[] htmlByte = new byte[uc.getContentLength()];这行错误。请大神告诉下我这个虾米
java.lang.NegativeArraySizeException错误,好像是说数组长度不正确,为什么呢