现在要抓http://www.csdn.net网页
为什么不能完整的抓下来
代码如下:String str = "http://www.csdn.net";
try
         {
             URL url = new URL(str);
             URLConnection urlCon =  url.openConnection();
             urlCon.setDoOutput(true);
             InputStream is = urlCon.getInputStream();
             System.out.println(is.available());
             byte [] rb = new byte[is.available()];
             is.read(rb);             FileOutputStream fos = new FileOutputStream("e:/test.txt");
             fos.write(rb);
             fos.flush();
             fos.close();
         }
         catch(Exception e)
         {
             System.out.println(e.toString());
         }为什么抓下来的数据就是不完整
麻烦大家帮我看看

解决方案 »

  1.   

    楼主干嘛不这样:
    in=new BufferedReader(new InputStreamReader(open.getInputStream()));
    while((temp=in.readLine())!=null){str.append(temp);str.append('\r');str.append('\n');}
    这样可以读完整。
      

  2.   

    谢谢楼上兄弟,那为什么is.available()不能很好的使用呢?为什么象楼上兄弟这样使用就可以完整的得到input流里面的内容呢?
      

  3.   

    各位 不好意思   我不知道在那里提问 有个关于URLCONNECTION的问题 urlconnection下载多框架网页 请问哪位专家 用urlconnection下载多框架网页 怎么实现 
    http请求头里有多框架设置么 jdk1.4支持么 
      

  4.   

    available() 
              Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.