现在要抓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());
}为什么抓下来的数据就是不完整
麻烦大家帮我看看
为什么不能完整的抓下来
代码如下: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());
}为什么抓下来的数据就是不完整
麻烦大家帮我看看
in=new BufferedReader(new InputStreamReader(open.getInputStream()));
while((temp=in.readLine())!=null){str.append(temp);str.append('\r');str.append('\n');}
这样可以读完整。
http请求头里有多框架设置么 jdk1.4支持么
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.