eclipse 输入下面内容怎么 len = -1
import java.net.*;
import java.io.*;
import java.util.Date;
public class URLdemo {
	/**
	 * @param args
	 */
	public static void main(String[] args)throws Exception {
		// TODO Auto-generated method stub
		int c ;
       URL hp = new URL("http://www.osborne.com");
       URLConnection hpcn = hp.openConnection();        
       System.out.println("Date:"+ new Date(hpcn.getDate()));
       System.out.println("content-type:"+ hpcn.getConnectTimeout());        
       System.out.println("expires:"+ hpcn.getExpiration());
       System.out.println("last-modeified:"+ new Date(hpcn.getLastModified()));
       int len = hpcn.getContentLength();        
       System.out.println("length:"+ len);
       if(len > 0)
       {
     	  System.out.println("===connection====");
     	  InputStream  input = hpcn.getInputStream();
     	  int i = len;
     	  while(((c = input.read())!= -1)&&(i-- > 0))
     	  {
     		  System.out.print((char)c);
     	  }
     	  input.close();
       }
       else
       {
        System.out.println("no content available");
       }
	}
}
是不是没连接上??和路由器什么的有关吗
------解决方案--------------------连接上了~~~~
------解决方案--------------------你尝试连接的网址会自动重定向到http://www.mhprofessional.com/templates/112-computing.php所以length会返回-1
至于为什么-1我也不清楚,我只是知道代码没什么大问题,就是连接网址的问题,如果URL换成http://www.tsinghua.edu.cn以html为主页的没有任何问题
------解决方案--------------------getContentLength():返回 content-length 头字段的值,或者如果内容长度未知,则返回 -1。
------解决方案--------------------[color=#FF0000]
Java code
  System.out.println("content-type:"+ hpcn.getConnectTimeout());